Vue自定义指令
### Vue.directive();有两个参数,第一个参数就是自定义指令的名称“字符串类型”,第二个参数是个函数或者对象
-
用法
-
指令里面的函数
-
bind:function(){}指令第一次被绑定到元素上面的时候调用,被调用多少次就执行多少次
<div id="app"> <p v-haha>{{msg}}</p> </div> <script> Vue.directive("haha",{ bind:function(){ console.log("bind"); } }); const app = new Vue({ el:"#app", data:{ msg:"你好" } }); </script>
-
inserted:function(){}当被绑定的元素插入到Dom中时调用,插入多少次调用多少次
inserted:function(){ console.log("hello"); }
-
update:function(){}当组件里的VNode更新时调用
update:function(){ console.log("更新了呀"); }
-
componentUpdated:function(){}当组件或者子组件的内容全部更新了之后调用
componentUpdated:function(){ console.log("全部更新了"); }
-
unbind:function(){}解绑,生命周期销毁执行后才会解绑
unbind:function(){ console.log("解绑了"); }
-
-