uni-app实现点赞评论功能
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要介绍了uni-app实现点赞评论功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们狼蚁网站SEO优化随着长沙网络推广来一起学习学习吧
模拟朋友圈实时点赞及评论功能
点赞思路点击的时候,使用push(点赞)以及slice(取消赞)方法处理数组,并且调用点赞接口
评论思路点击的时候,写多一个评论列表,当点击发送的时候mentStatus=true,且索引等于点击的索引。调用获取评论列表的接口
html
<view class="toolbar"> <view class="timestamp">{{item.timetype}}</view> <!-- 点赞 如果islove==1,图片变为点赞的图片--> <view class="like" @tap="like(index,item.id)"> <image :src="item.islove==1?'../../static/images/lllllike.png':'../../static/images/llike.png'"></image> </view> <!-- 评论 --> <view class="ment" @tap="ment(index,item.id)"> <image src="../../static/images/pinglun.png"></image> </view> </view> <!-- 赞/评论区 --> <view class="post-footer"> <!-- 点赞区 --> <view class="footer_content" v-if="item.lovelist.length>0"> <image class="liked" src="../../static/images/likelike.png"></image> <text class="nickname" v-for="(love,love_index) of item.lovelist" :key="love_index">{{love.name}},</text> </view> <!-- 评论区 --> <view class="footer_content" v-if="item.munity_on.length>0" v-for="(ment,ment_index) in item.munity_on" :key="ment_index"> <text class="ment-nickname">{{ment.nickname}}: <text class="ment-content">{{ment.content}}</text></text> </view> <!-- 当评论发送成功之后实时渲染出来评论列表--> <view class="footer_content" v-if="mentStatus && index==mentIndex"> <text class="ment-nickname">{{realtimename}}: <text class="ment-content">{{realtimecontent}}</text></text> </view> </view>
// 点赞 like(index,munityId) { if (this.munity[index].islove == 0) { this.munity[index].islove = 1; this.munity[index].lovelist.push( {name:this.userinfo.nickname,id:this.userinfo.id} ) this.likeImport(munityId) } else { this.munity[index].islove = 0; this.munity[index].lovelist.splice(this.munity[index].lovelist.indexOf(this.userinfo.nickname), 1) this.likeImport(munityId) } }, // 点赞接口 likeImport(id) { app.idRequest({ url: 'Vip/munity_love', data: { id: id }, header: { 'content-type': 'application/x--form-urlencoded', }, method: 'POST', suess:(res) => { if(res.data.status) { } else { console.log(res.data) } } }) },
// 点击评论 ment(index,munityId) { this.showInput = true; //调起input框 this.focus = true; // 对焦 this.munityId = munityId }, // 点击发送 send_ment: function(message) { this.mentStatus = true this.mentIndex = index this.realtimecontent = message.content this.realtimename = this.userinfo.nickname app.idRequest({ url: 'Vip/munity_on', data: { id: this.munityId, content: message.content, type: 1 }, header: { 'content-type': 'application/x--form-urlencoded', }, method: 'POST', suess:(res) => { if(res.data.status) { this.getCommunity() // 整个页面数据刷新 this.init_input() this.mentStatus = false // 临时渲染评论的列表隐藏 this.realtimecontent = '' this.realtimename = '' this.input_placeholder = '评论'; } else { console.log(res.data) } } }) } // 取消评论/评论完成输入框状态值 init_input() { this.showInput = false; this.focus = false; this.input_placeholder = '评论'; this.is_reply = false; },
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 甘肃哪有关键词排名优化购买方式有哪些
- 甘肃SEO如何做网站优化
- 河南seo关键词优化怎么做电话营销
- 北京SEO优化如何做QQ群营销
- 来宾百度关键词排名:提升您网站曝光率的关键
- 卢龙关键词优化:提升您网站排名的策略与技巧
- 山东网站优化的注意事项有哪些
- 四川整站优化怎样提升在搜索引擎中的排名
- 疏附整站优化:提升网站性能与用户体验的全新
- 海南seo主要做什么工作售后服务要做到哪些
- 荣昌百度网站优化:提升您网站的搜索引擎排名
- 河北seo网站排名关键词优化如何做SEO
- 江西优化关键词排名推广售后保障一般有哪些
- 古浪SEO优化:提升你的网站可见性
- 西藏网站排名优化怎么把网站排名在百度首页
- 如何提升阳东百度快照排名:详尽指南