在美国vps的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’;
}
}