1. <template里面>添加 @input 事件
<el-table-column label="拆分数量">
<template slot-scope="scope">
<el-input v-model="scope.row.num" @input="e => (scope.row.num = isnumber(e))">
</el-input>
</template>
</el-table-column>
2.methods内添加方法
isnumber (val) {
val = val.replace(/\b(0+)+[^0-9]*/gi, "");
return val;
},
3.这里有一个坑,就是如果对于列表循环出来的 @input失效 原因在于在Vue实例创建时,obj.b并未声明,因此就没有被Vue转换为响应式的属性,自然就不会触发视图的更新
// 这是错误写法, vue实例 v-model 失效
this.list.forEach((item,index,arr) => {
item.num = '1'
})
// 正确写法, 使用 $set 初始值
this.list.forEach((item,index,arr) => {
this.$set(item, 'num', '1')
})