• 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比较做出提示

  • 相关阅读:
    JS随笔
    tp5 redis 单例模式 转载
    分享我编程工作经历及对软件开发前景的看法
    redis详解(一)-- 概述
    redis详解(二)-- 数据类型详解
    redis详解(四)-- 高可用分布式集群
    redis详解(三)
    新工科平台
    关于Nginx的负载均衡
    微信退款回调
  • 原文地址:https://www.cnblogs.com/chenyangjava/p/15351974.html
Copyright © 2020-2023  润新知