自定义指令总结:
一、定义语法:
局部指令
写法1://对象式new Vue({ directives:{指令名:配置对象} })写法2: //函数式
new Vue({ directives{指令名:回调函数} })全局指令:
写法1: //对象式Vue.directive(指令名,配置对象)写法2: //函数式
Vue.directive(指令名,回调函数)
二、配置对象中常用的3个回调:
- bind:指令与元素 成功绑定时 调用。
- inserted:指令所在元素 被插入页面时 调用。
- update:指令所在模板结构 被重新解析时 调用。
三、备注:
- 指令定义时不加v-,但使用时要加v-;
- 指令名如果是多个单词,要使用kebab-case命名方式,不要用camelCase驼峰命名。
