需求是需要将 Code 录入的字母转为大写
指令注册
import upperCase from "./upperCase";
const install = function (Vue) {
Vue.directive("upperCase", upperCase);
};
if (window.Vue) {
window["upperCase"] = upperCase;
}
export default install;
Vue.use(directiveUtils);
方式一
可以实时的去更改当前录入的字母,但是经过试验会有个
Bug
,如果是用的v-model
绑定的数据,用中文输入法输入的字母(比如我当前 用中文输入法输入 Barry,然后按1选中输入的内容),无法更新到v-model
绑定的数据
/**
* 字母转大写
*/
function inputHandler(e) {
e.target.value = e.target.value.toUpperCase