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