vue之键盘修饰符以及自定义键盘修饰符
1.自定义键盘修饰符【了解】
Vue.directive('on').keyCodes.f2 = 13;
2.自定义键盘修饰符
- 通过
Vue.config.keyCodes.名称 = 按键值
来自定义案件修饰符的别名:
Vue.config.keyCodes.f2 = 13;
- 使用自定义的按键修饰符:
<input type="text" v-model="name" @keyup.f2="add">
3. 自定义指令
- 自定义全局和局部的 自定义指令:
Vue.directive('focus', {
inserted: function (el) {
el.focus();
}
});
directives: {
color: {
bind(el, binding) {
el.style.color = binding.value;
}
},
'font-weight': function (el, binding2) {
el.style.fontWeight = binding2.value;
}
}
- 自定义指令的使用方式:
<input type="text" v-model="searchName" v-focus v-color="'red'" v-font-weight="900">
js 里面的键盘事件对应的键码