学无先后,达者为师

网站首页 Vue 正文

vue 中使用input number类型 maxlength失效

作者:逃跑小刀 更新时间: 2022-03-01 Vue

vue中使用el-input不好用,想只能输入数字,且最大长度10 ,但是maxlength属性不管用

于是

template

 <input
                type="number"
                v-model="userId"
                @input="changeNum"
                placeholder="请填写用户ID"
              />
script
 data : userId

 methods:
    changeNum: function(e) {
      //限制长度
      if(this.userId.length>10){
        this.userId=this.userId.slice(0,10)
      }
    },

style
 //隐藏箭头
 input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
input[type="number"] {
  -moz-appearance: textfield;
}

 

原文链接:https://blog.csdn.net/lishi9092/article/details/99673379

栏目分类
最近更新