WeChat applet implementation of like, delete list and sharing functions

不言
Release: 2018-06-26 15:33:45
Original
4689 people have browsed it

This article mainly introduces the WeChat mini program project summary of the like and delete list sharing function. This article introduces it to you in very detail and has certain reference value. Friends who need it can refer to it

Like function of mini program

Idea: There is no interface for you to simulate data in the background

data:{ likes:{ iszan:false, num:0 } }
Copy after login

1. Traverse the comment list to determine the clicked id

2. If the id is the same, determine whether it has been liked. If it is true -1 if it is false 1

3. Update data

bindlike:function(e){ var newData = this.data.release.map(function(item){ if (item.id == e.currentTarget.dataset.id){ console.log(item.id + e.currentTarget.dataset.id ) if(item.likes.iszan){ var obj = {} obj.iszan = !item.likes.iszan; obj.num = item.likes.num -1 ; return Object.assign({},item,{likes:obj}) }else { var obj = {} obj.iszan = !item.likes.iszan; obj.num = item.likes.num + 1; return Object.assign({}, item, { likes: obj }) } }else { return item } }) this.setData ({ release:newData }) },
Copy after login

## 2. Click the delete list function

1. Bind the id to the undo button and add a click event

2. When you click the delete button, you will be prompted whether to delete it

3. If the user clicks OK to get the id to be deleted

4. Delete the corresponding array content

5. Update the data

//删除评论 binddelete:function(e){ var that = this; wx.showModal({ title: '提示', content: '确认撤回吗?', success:function(res){ if(res.confirm){ console.log('用户点击确定') // 获取要删除数据的id var dataid = e.currentTarget.dataset.id; console.log(dataid) // 删除数组对应的数据内容 var release = that.data.release; that.data.release.splice(dataid,1) //判断数据的长度 var len = that.data.release.length; //通过判断数组的长度来决定是否显示隐藏的部分 that.setData ({ release: that.data.release }) }else if(res.cancel){ console.log('用户点击取消') } } }) },
Copy after login

3. Click to share

Click the share button to bind a

open-type = "share"Attribute

By setting the attribute

open-type="share" to the button component,can be triggered after the user clicks the buttonPage.onShareAppMessage()Event, if this event is not defined on the current page, there will be no effect after clicking.

Page({ onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res.target) } return { title: '自定义转发标题', path: '/page/user?id=123' } } })
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Implementation of rolling message notifications in WeChat applet

WeChat applet development One-click login acquisition Implementation of session_key and openid

The above is the detailed content of WeChat applet implementation of like, delete list and sharing functions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!