vue取自动生成的数组中单个元素的值

直接上代码:

1.add.vue页面

<view class="" v-for="(item,i) in detailTimePricesyd" :key="item">
      <!-- 时段/价格 -->
      <text class="uuu" v-if="item.salePrice!=0">{{i18n.SBD_Period_Price}}</text>
      <view :class="acb" v-if="item.salePrice!=0">
            <view class="sss">
                  <input class="uni-input" type="number" @input="onkeyInput" :data-type="'beginTime'+'-'+i" :v-model="'beginTime'+i"
                       maxlength="2" :value="item.beginTime" :name="'beginTime'+'-'+i" placeholder=" " />
            </view>
            <text class="szz">--</text>
            <view class="sss">
                  <input class="uni-input" type="number" @input="onkeyInput" :data-type="'endTime'+'-'+i" :v-model="'endTime'+i"
                       maxlength="2" :value="item.endTime" :name="'endTime'+'-'+i" placeholder=" " />
            </view>
            <!-- 时 -->
            <text class="szz">{{i18n.SBD_Hour}}</text>
            <view class="ssl">
                  <input class="ppi" type="number" maxlength="5" :value="item.salePrice"
                      :name="'salePrice'+'-'+i" placeholder=" " />
            </view>
            <image src="../../static/img/sta/sc_h.png" @click="deleteSw(i)" :class="ssh"></image>
      </view>
      <text class="hx" v-if="item.salePrice!=0"></text>
</view>
 

2.在method方法里拿单个beginTime数据

onkeyInput(e) {
                let type = e.currentTarget.dataset.type
                let from = 0;
                let to = 20;
                for (; from < to; from++) {
                    if (type == 'beginTime-'+from) {
                        let beginTime0 = e.target.value
                        if (beginTime0 > 24) {
                            uni.showToast({
                                icon: 'none',
                                title: this.SBD_greater_than_24
                            });
                            return
                        }
                        if (beginTime0 < 0) {
                            uni.showToast({
                                icon: 'none',
                                title: this.SBD_greater_than_0
                            });
                            return
                        }
                    }
                    if (type == 'endTime-'+from) {
                        let endTime0 = e.target.value
                        if (endTime0 > 24) {
                            uni.showToast({
                                icon: 'none',
                                title: this.SBD_greater_than_24
                            });
                            return
                        }
                        if (endTime0 < 0) {
                            uni.showToast({
                                icon: 'none',
                                title: this.SBD_greater_than_0
                            });
                            return
                        }
                    }
                }
            },
            

 在onkeyInput方法里能拿到单个beginTime跟0和24比较做出提示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gh786395613

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值