Vue 自定义指令简单使用
main.js
//指令--1 Vue.directive('my-fei-directive', { inserted: function (el, binging, vnode, oldVnode) { el.focus(); el.style.borderColor = "red"; el.value = "我是fei"; } }); //指令--2 Vue.directive('my-fei-directive2', { inserted: function (el, binging, vnode, oldVnode) { console.log(binging.value); el.focus(); el.style.borderColor = binging.value.color; el.value = binging.value.text; } });
demo.vue
<input type="text" v-my-fei-directive> <input type="text" v-my-fei-directive2="{color:'blue',text:'图书_论语'}">
扩展: Vue 自定义指令