//判断val 只能输入数字和小数点
getInput(val) {//input事件函数
console.log("input事件");
this.value=this.value.replace(/[^\d.]/g, "")
console.log(this.value)
},
运行上面代码发现value的值改变了但是input中显示的内容未改变
解决方式
1.this.$nextTick()
//判断val 只能输入数字和小数点
getInput(val) {//input事件函数
console.log("input事件");
this.$nextTick(()=>{
this.value=this.value.replace(/[^\d.]/g, "")
console.log(this.value)
})
},
2.添加延迟settimout
//判断val 只能输入数字和小数点
getInput(val) {//input事件函数
console.log("input事件");
setTimeout(()=>{
this.value=this.value.replace(/[^\d.]/g, "")
console.log(this.value)
},0)
},