首页 > 其他 > 详细

vue 实现点赞

时间:2018-01-29 18:06:12      阅读:507      评论:0      收藏:0      [点我收藏+]

在v-for循环里

<ul class="project_content">
			<li v-for="(item, index) in items" :key="index" v-if="index%2==0">
	        	<div class="project_wrap clearfix">
			      <router-link :to="{path:‘/detail‘,query: { id: item.goods_id }}" class=‘project_inner‘>
			        <img :src="item.original_img" class=‘original_img‘>
			      </router-link>
			      <div class="article_name">{{item.article_name}}</div>
			        <div class="article_message">
				        <div class="user_info">
				        	<div class="user_img"><img :src="item.user_img" ></div>
				          <span class="user_name">{{item.user_name}}</span>
				        </div>
			          <div class="article_likes" @click="dolikes(index)"><span v-bind:class="[item.likesbefore? ‘likesbefore‘:‘likesafter‘]"></span><span class="likes" v-bind:class="[item.likesbefore ? ‘gray‘:‘pink‘]">{{item.likes}}</span></div>
			        </div>
			  	</div>
      		</li>
		</ul>

  

函数带上index

 

methods: {
//时间操作函数执行
dolikes(index){
  console.log(this.items[index])
  this.items[index].likes = this.items[index].likesbefore ?parseInt(this.items[index].likes) +1:parseInt(this.items[index].likes) -1
  this.items[index].likesbefore=!this.items[index].likesbefore;
  console.log(this.items[index].likesbefore)
  }

vue 实现点赞

原文:https://www.cnblogs.com/zhoubingyan/p/8378660.html

(1)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!