el-input类型为number时禁止输入e和.

<el-form-item label="一级渠道码" prop="first_channel_code">
  <el-input type="number" v-model.number="ruleForm.first_channel_code" @keydown.native="channelInputLimit"></el-input>
</el-form-item>

// bug fix:指定输入类型为number时仍然可以输入字母'e'和小数点'.'(因为也属于数字类型的范围),这里做一下输入限制
channelInputLimit (e) {
  let key = e.key
  // 不允许输入'e'和'.'
  if (key === 'e' || key === '.') {
    e.returnValue = false
    return false
  }
  return true
}

  

猜你喜欢

转载自www.cnblogs.com/chunshu/p/11750323.html
今日推荐