- 首先是wxml中(登录用户)
<!-- 只是模拟小部分数据 -->
<block wx:for='{{threeDemo}}' wx:key>
<view class="flex imgWidth">
<view>
<image src="../../img/indexDetail/false.png">
</image>
</view>
<view class="contentOrd">
<view>阿银</view>
<view>家具家居设计风格重要,而且一旦定下来也很难改变。</view>
<view class="flexData">
<view>23:19</view>
<view>
<!-- istype返回的就是是否是点赞的登录用户的 -->
<text class="cuIcon-appreciatefill lg {{item.istype?'text-blue':'text-grey'}}" bindtap="clickAddUp" data-item='{{item}}' data-id='{{index}}'></text>
<text class="marginLeft10">{{item.count}}</text>
<text class="cuIcon-message lg text-grey marginLeft20" bindtap="showModal"></text>
</view>
</view>
</view>
</view>
</block>
- 其次是js中
var app = getApp();
const api = require("../../api/api.js")
const requestAjax = require("../../api/request.js")
Page({
data: {
threeDemo: [{
id: 0,
istype: true,
count: 122
}, {
id: 1,
istype: false,
count: 100
}, {
id: 2,
istype: false,
count: 90
}]
},
clickAddUp(e) {
if (this.data.threeDemo[e.currentTarget.dataset.id].istype === false) {
this.data.threeDemo[e.currentTarget.dataset.id].count++
} else {
this.data.threeDemo[e.currentTarget.dataset.id].count--
}
this.data.threeDemo[e.currentTarget.dataset.id].istype = !this.data.threeDemo[e.currentTarget.dataset.id].istype
this.setData({
threeDemo: this.data.threeDemo
})
},
})