vue中输入框只能输入数字

  方案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="请输入流量分配" />

猜你喜欢

转载自www.cnblogs.com/ChineseLiao/p/11843879.html