<el-input v-model="testData" @keydown.native="checkNumber"></el-input>
- 只能使用keydown或者keyup事件
checkNumber(e) {
// 此處可以自行定義正則規則
const reg = /^[1-9]\d*$/;
if (e.key === 'Backspace') {
return true;
}
if (!reg.test(e.key)) {
e.returnValue = false;
return false;
}
return true;
},