例如如下代码:
<input type="text" v-model="sellPrice">
<input type="text" v-model="buyVolume">
reg:/^[0-9]+(.[0-9]{1,8})?$/
reg1:/[0-9]d*/
watch:{
buyPrice:function(){
},
sellPrice:function(){
let a = this.sellPrice;
this.sellPrice = a.match(this.reg,'');
},
buyVolume:function(){
this.buyVolume = this.buyVolume.match(/[0-9]\d*/,'');
},
sellVolume:function(){
this.sellVolume = this.sellVolume.match(/[0-9]\d*/,'');
}
}
Price无法成功。
为什么sellVolume能成功但是会报this.sellVolume.match is not a function
match得到的是个数组所以报错而且正则应该是/^[0-9]d$|(^[0-9]+.[0-9]{0,8})/,watch检测数据是没问题的。用computed反而会麻烦一些