在vue中自定义指令的方法有:语法:Vue.directive(id, definition);1.自定义全局指令;2.自定义私有指令;
在vue中自定义指令的方法有以下两种
vue自定义指令语法:
Vue.directive(id, definition)
1.自定义全局指令
Vue.directive('focus', { bind: function (el) {
el.focus()
},
inserted: function (el) {
el.focus()
},
updated: function () {
}
});
2.自定义私有指令
directives: { 'fontweight': {
bind: function (el, bingding) {
el.style.fontWeight = bingding.value;
}
},
'fontsize': function (el, bingding) {
el.style.fontSize = parseInt(bingding.value) + 'px';
}
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php自定义函数的方法有哪些