查看: 323|回复: 0

[uniapp] 在列表中怎么获取点击的input的输入值

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2025-11-14 18:37:14 | 显示全部楼层 |阅读模式
html代码:

  1. <view class="nui-category-box" v-for="(item, index) in items" :key="index">
  2.                                 <view class="nui-category-left">
  3.                                         {{item.title}}
  4.                                 </view>
  5.                                 <view class="nui-category-right">
  6.                                         <view class="nui-category-item">{{item.price}}</view>
  7.                                         <view class="nui-category-item">{{item.unit}}</view>
  8.                                         <view class="nui-category-item">
  9.                                                 <input type="number" class="nui-input" v-model="item.total" @input="inputTotal(index)" />
  10.                                         </view>
  11.                                 </view>
  12.                         </view>
复制代码


js代码:
  1. // 输入数量
  2.                         inputTotal(index) {
  3.                                 console.log(index)
  4.                                 const value = this.items[index].total;
  5.                                 if (value <= 0) {
  6.                                         this.items[index].total = '';
  7.                                 }
  8.                                 console.log(`第${index + 1}个input的值:`, value);
  9.                                 console.log(this.items)
  10.                                 let that = this;
  11.                                 that.tui.request('order/sumtotal', {
  12.                                         items: JSON.stringify(that.items)
  13.                                 }).then((res) => {
  14.                                         console.log(res)
  15.                                         if (res.code == 1) {
  16.                                                 that.amount = res.data.amount;
  17.                                         }
  18.                                 })
  19.                         },
复制代码
使用v-model进行数据双向绑定。
道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部