Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does WeChat Mini Programs realize the functions of giving likes, deleting lists and sharing?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to like WeChat Mini Programs, delete the list, and share", so the editor summarizes the following contents for you. The content is detailed, the steps are clear, and it has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "WeChat Mini Programs how to like, delete the list, share the function" article.

Like function of Mini Program

Idea: you are not given an interface to simulate your own data in the background.

Data: {likes: {iszan:false, num:0}}

1. Go through the comment list to determine which id is clicked

two。 If id judges whether it has been liked or not, 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})}

two。 Click to delete list function

1. Add a click event to the undo button bind id

two。 Prompt whether to delete when you click the delete button

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

4. Delete the corresponding array contents

5. Update data

/ / Delete comments binddelete:function (e) {var that = this; wx.showModal ({title: 'prompt', content: 'confirm withdrawal?' , success:function (res) {if (res.confirm) {console.log ('user clicks OK') / / get id var dataid = e.currentTarget.dataset.id; console.log (dataid) / / delete the data content corresponding to the array var release = that.data.release; that.data.release.splice (dataid,1) / / determine the length of the data var len = that.data.release.length / / decide whether to show the hidden part that.setData ({release: that.data.release})} else if (res.cancel) {console.log ('user click cancel')} by judging the length of the array.

3. Click to share

Click the share button to bind an open-type = "share" attribute to the button button

By setting the property open-type= "share" to the button component, the Page.onShareAppMessage () event can be triggered after the user clicks the button, and if this event is not defined on the current page, the click has no effect.

Page ({onShareAppMessage: function (res) {if (res.from = 'button') {/ / from the on-page forwarding button console.log (res.target)} return {title:' custom forwarding title', path:'/ page/user?id=123'}) these are the contents of this article about "how WeChat Mini Programs can like, delete list and share" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report