In vue, the input input box only allows numbers to be entered

In the vue project, the input box only allows numbers to be entered. Now I will record a method I use for your reference.

The vue modifier is needed here

Students who don't understand can go to the official website of vue to see, or Baidu to see the explanations of other documents.

.number

If you want to automatically convert the user's input value to a numeric type, you can add v-modela numbermodifier:

<input v-model.number="age" type="text" />

textThis is often useful when the input type is a string type.

If the input type is number, Vue is able to automatically convert the raw string to a number without v-modeladding .numbermodifiers.

If the value cannot be  parseFloat() parsed, the original value is returned.

Solution

Inline insertion οninput="value=value.replace(/[^0-9.]/g,' ')"

<el-input v-model.number="numVal" placeholder="请输入数字(限数字)" 
  oninput="value=value.replace(/[^0-9.]/g,'')" />

This article ends.

Guess you like

Origin blog.csdn.net/weixin_43743175/article/details/125165770