Solve the problem that when using element ui, the attribute type=number of el-input can still input e.

When using element ui, the attribute type=number of el-input can still be entered.
Other Chinese special characters cannot be entered, but only e can be entered. The reason is that when e is also entered as scientific notation, e is It can be judged as digital,
but in some scenarios it is necessary to shield e from this situation. We can use the following method.
When inputting keyboard events, monitor and prohibit the input of e.
Methods as below.

<el-input
    @keydown.native="handleInput"
    type="number"
    v-model="form.number"
    clearable
    placeholder=""
  ></el-input> </el-form-item>
      handleInput(e) {
    
    
        let key = e.key;
        if (key === 'e' || key === 'E' || key === '+' || key === '-' || key === '.') {
    
    
          e.returnValue = false;
          return false;
        }
        return true;
      },

It can be solved by the above method.

Guess you like

Origin blog.csdn.net/m54584mnkj/article/details/132360239