方案1:增加自定义指令
自定义指令写法:
directives: {
numberOnly: {
bind(el) {
el.handler = function () {
el.value = el.value.replace(/D+/, '');
};
el.addEventListener('input', el.handler);
},
unbind(el) {
el.removeEventListener('input', el.handler);
}
}
},
组件写法:
<Input v-model="row.Weight" v-number-only placeholder="请输入流量分配" />