<block v-for="(row, index) in titleImgArr"> <view class="titleimg-sel"> <image class="titleimg-sel-img" @tap="tabCommonClick" data-value="{index}" data-field="titleImgIndex" :src="'/static/image/indextitle/' + row.url"></image> </view> </block> uniapp这样写js获取到的value为什么是index而不是index值
时间: 2023-07-08 22:17:40 浏览: 53
这个问题出在 `data-value="{index}"` 这里,这样写会把 `data-value` 的值直接设置为字符串 `"{index}"`,而不是变量 `index` 的值。因此,在事件监听函数中获取到的值就是字符串 `"{index}"` 而不是变量 `index` 的值。
正确的写法应该是使用 `v-bind` 或简写的 `:` 来绑定动态值,如下所示:
```html
<block v-for="(row, index) in titleImgArr">
<view class="titleimg-sel">
<image class="titleimg-sel-img" @tap="tabCommonClick" :data-value="index" data-field="titleImgIndex" :src="'/static/image/indextitle/' + row.url"></image>
</view>
</block>
```
这样,在 `data-value` 中就能正确地绑定变量 `index` 的值了。
相关问题
<select id='sel1' v-model="select1" @change="count"> <option v-for="c in countryList" :key="c.id" :value="c.id"> {{c.name}} </option> </select> <input id='in1' type="text" v-model="v"> ≈ <select id='sel2' v-model="select2" @change="count"> <option v-for="c in countryList" :key="c.id" :value="c.id"> {{c.name}} </option> </select>这段代码中@change是干嘛用的
?@change是一个 Vue.js 框架中的事件,当选项被改变时会触发相应的操作。在这段代码中,当第一个下拉菜单(id为sel1)或第二个下拉菜单(id为sel2)的选项被改变时,都会触发定义在Vue实例中的count方法。
<scroll-view class="container" scroll-y="true" wx:if="{{hidden==false}}"> <block wx:for="{{orderList}}" wx:key=""> <view class="orderList"> <view class="order-title"> <view class="order-title-restaurantName"> {{item.canteen}}</view> <view class="order-title-state" wx:if="{{item.type==0}}">堂食</view> <view class="order-title-state" wx:else>打包</view> </view> <view class="order-content"> <image class="order-content-restaurantImg" src="https://www.zzyqzs.com/static/upload/image/20220301/1646118325920051.jpg"></image> <view class="order-content-info"> <view class="order-content-info-price">¥ {{item.money}}</view> <view class="order-content-info-date"> {{item.date}}</view> <view class="order-content-info-howToDistribute"> 由 山东农业大学 提供服务</view> </view> </view> <view class="order-footer"> <view class="order-footer-orderAgain" bindtap="sel1" data-dorderuid="{{item.id}}">评论</view> <view class="order-footer-orderAgain" bindtap="sel" data-dorderuid="{{item.d_id}}">查看详情</view> <view class="order-footer-orderAgain" bindtap="zl" data-canteen="{{item.canteen}}">再来一单</view> </view> </view> </block> </scroll-view>
这是一个小程序的代码,其中使用了微信小程序的组件和指令。其中使用了一个scroll-view组件来实现滚动视图的效果,wx:if指令用于控制是否显示该组件。在scroll-view中使用了一个block和wx:for指令来循环渲染订单列表,使用了{{}}绑定数据。每个订单项包括餐厅名称、订单类型、订单内容等,并且每个订单项都有一个订单底部操作栏,可进行评论、查看详情、再来一单等操作。