4 回答
TA贡献1772条经验 获得超6个赞
亲测完美解决 并且限制除数字以外一切字符的输入
computed 计算属性的 getter setter 是很有用的属性
<input type=text v-model="value2">
data() {
return {
value1: "10"
};
},
computed: {
value2: {
get() {
var value = this.value1.replace(/[^\d]+/g, '');
if(value<=0){
return 0
}else if(value>=100){
return 100
}else{
return value
}
},
set(val) {
this.value1 = val;
}
}
},
TA贡献1条经验 获得超0个赞
<el-input
@keyup.native="scope.row.release_proportion=loadNumber(scope.row)"
type="text"
placeholder="填100以内的整数" v-model="scope.row.release_proportion" >
</el-input>
loadNumber(row){
var elValue = row.release_proportion
var reg = /^((?!0)\d{1,2})$/;
if (!reg.test(elValue)) {
row.release_proportion = "";
}
return row.release_proportion
},
- 4 回答
- 0 关注
- 25167 浏览
添加回答
举报