我们在获取后端数据的时候,有时候会在列表中生成很多的input,而我们又想实时监听这些input时要如何处理呢
<tr v-for="(item,index) in bstp" v-if="bstp">
<td><input type="text" name="" @input="newVal(index,item.value)" v-model="item.value"></td>
</tr>
使用方法在input值发生改变时修改数据
newVal(index,v){
let n=parseInt(v);
if(n<0 || isNaN(n)){
n=0;
}
this.bstp[index].value=n;
}

本文介绍了一种在Vue.js中实时监听动态生成的输入框(input)列表值变化的方法,通过v-for指令遍历数据并使用v-model双向绑定,结合自定义方法newVal更新数据,确保数据的一致性和实时性。
246

被折叠的 条评论
为什么被折叠?



