限制input type 为number 时 maxlength 无效

js版:

  <input  oninput= (val) => {if(val.length>11)return val.sliece(0,11)}>

vue版:

  <el-input   v-on:input="watchInput" v-model='input'></el-input>

  data(){

    return {

      input:''

    }  

  },

  methods:{

    watchInput(val){

      if(val.length>10){

        this.input = val.slice(0,10)

      }

    }

  }

猜你喜欢

转载自www.cnblogs.com/tutao1995/p/11912436.html