使用组件,当我输入内容时,它有一个限制条件,只能输入数字长度为8,并且只能输入2个小数点,例如,可以输入123.45,123.456不能。
<input :type="type"
v-model="inputValue"
:max-length="maxInputLength"
:maxlength="maxInputLength"
:placeholder="rightPlaceholder"
:class="['input', disabled ? 'input-style-disabled' : '']"
:disabled="disabled"
@input="onTextChange"/>
数据是:
data () {
return {
inputValue:'', //input value
}
},
mounted(){
if(this.value) {
this.inputValue = this.value;
}
},
methods:{
formatAmount(value){
let result;
if (value.indexOf(".") > 0 && value.length - value.indexOf(".") >= 4){
result = value.substr(0,value.indexOf('.') + 3);
// fValue = value.toFixed(2);
Log.d("formatAmount",result);
}else {
result = value;
Log.d("formatAmount else",result);
}
return result;
},
onTextChange() {
setTimeout(() => {
this.inputValue = this.formatAmount(this.inputValue);
this.$emit("onTextChange",this.inputValue);
}, 10);
}
}
总而言之,这只是在两点变为三点时起作用,然后仍然可以输入三点。
它是如何工作的,需要帮助。thx。