vue自定义指令
可以使用Vue.directive( ‘指令名称’ , {} ) 来定义全局自定义指令也可以使用 directives{ 指令名称 : {} } 来定义局部自定义指令
全局自定义指令
<div id="app">
<input type="text" v-focus />
</div>
Vue.directive('focus',{
inserted:function(el){
el.focus();
}
});
var vm = new Vue({
el:"#app",
data:{
msg:""
},
methods:{
}
})
局部自定义指令
<div id="app">
<input type="text" v-focus />
</div>
var vm = new Vue({
el:"#app",
data:{
msg:""
},
methods:{
},
//局部指令
directives:{
focus:{
inserted:function(el){
el.focus();
}
}
}
})