在列表中怎么获取点击的input的输入值
html代码:<view class="nui-category-box" v-for="(item, index) in items" :key="index">
<view class="nui-category-left">
{{item.title}}
</view>
<view class="nui-category-right">
<view class="nui-category-item">{{item.price}}</view>
<view class="nui-category-item">{{item.unit}}</view>
<view class="nui-category-item">
<input type="number" class="nui-input" v-model="item.total" @input="inputTotal(index)" />
</view>
</view>
</view>
js代码:
// 输入数量
inputTotal(index) {
console.log(index)
const value = this.items.total;
if (value <= 0) {
this.items.total = '';
}
console.log(`第${index + 1}个input的值:`, value);
console.log(this.items)
let that = this;
that.tui.request('order/sumtotal', {
items: JSON.stringify(that.items)
}).then((res) => {
console.log(res)
if (res.code == 1) {
that.amount = res.data.amount;
}
})
},使用v-model进行数据双向绑定。
页:
[1]