onlyNum.js
import Vue from 'vue'
//只对input生效
export default function (el) {
var input = el;
input.onkeyup = function (e) {
if(input.value.length==1){
input.value = input.value.replace(/[^1-9]/g,'');
}else{
input.value = input.value.replace(/[^\d]/g, "");
}
};
}
main.js
import limitNum from './directive/onlyNum'
Vue.directive('limitNum', limitNum);
Just add v-limitNum will be able to enter into force on the input of the component.
More professional front-end knowledge, make the [2048] ape www.mk2048.com