Vue进阶属性
directives
, mixins
, extends
, provide
, inject
内置指令
v-if
,v-for
,v-show
,v-html
自定义指令
声明一个全局指令
Vue.directive('x',directiveOptions)
就可以在任何组件里使用v-x
了
directiveOptions
是选项
声明一个局部指令
new Vue({
...,
directives: {
"x": directiveOptions
}
})
//v-x只能在该实例中使用。
directiveOptions
- bind(el, info, vnode, oldVnode)-类似created
- inserted(参数同上)-类似mounted
- update(参数同上)-类似updated
- componentUpdated(参数同上)-用的不多
- unbind(参数同上)-类似destroyed
el:绑定的元素
info:除了传元素之外,还传了那些东西(详细的信息)
vnode:元素对应的虚拟节点
oldVnode:之前的虚拟节点
模仿v-on
import Vue