如何在vue循环列表中实现点赞改变icon和字体颜色,不可取消点赞
1,在项目中将icon变成字体图标,如何引入的话可以百度一下2.页面操作代码如下
·
1,在项目中将icon变成字体图标,
参考以下链接:
https://jingyan.baidu.com/article/d45ad1485e549569552b80c1.html
2.页面操作代码如下
<div v-for='(item,index) in list' :key='index'>
<span class='margin-left-normal' @click='bindLike(item,index)'>
<span :id="'vote'+index">
<i class="iconfont icon-dianzan" ></i> 点赞图标
<span class=' text-right font-size-smaller margin-right-small' >{{ item.number}}</span>点赞数量
</span>
</span>
</div>
js部分
<script>
export defalut{
data(){
return {
countVote :'',
list:[
{number:1}, {number:1}, {number:1},
]
}
},
methods:{
bindLike (item, index) {
this.countVote = item.number
if (this.countVote != 0) {
this.showPosition = true 这是用来判断已点赞之后再次点赞的弹框的
} else {
document.getElementById('vote' + index).classList.add('red')
item.number++
this.showPositionValue = true 这是用来判断点赞的弹框的
}
},
}
}
</script>
更多推荐
已为社区贡献3条内容
所有评论(0)