Get the App
SLTechnology News&Howtos  ›  Development  › 

How to encapsulate JS Wechat sharing

Shulou Source: shulou.com Published: 2022-06-02 14:15:39 09月30日 Update

This article mainly explains "how to encapsulate JS Wechat sharing", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to encapsulate JS Wechat sharing.

My train of thought:

1. Can share to four places QQ, friends, moments, Weibo, generally they are the same, you can configure an initial parameter, assign values to them four

two。 If there is an inconsistency, because the initial parameters have been assigned previously, replace the content that needs to be inconsistent.

Implement the main code:

SetData: function () {var self = this Self.data = {title: self.title, desc: self.desc, link: self.link, imgUrl: self.imgUrl, type: self.type, / / sharing type, music, video or link. If left empty, the default is link dataUrl: self.dataUrl, / / if type is music or video, provide a data link Default is empty success: self.success, cancel: self.cancel} / / Deep cloning self.QQData = JSON.stringify (self.data); self.QQData = JSON.parse (self.QQData); self.TimeLineData = JSON.stringify (self.data); self.TimeLineData = JSON.parse (self.TimeLineData); self.WeiBoData = JSON.stringify (self.data); self.WeiBoData = JSON.parse (self.WeiBoData) / / deserialize self.QQData.success = self.success; self.TimeLineData.success = self.success; self.WeiBoData.success = self.success; self.QQData.cancel = self.cancel; self.TimeLineData.cancel = self.cancel; self.WeiBoData.cancel = self.cancel;} wx.ready (function () {wx.showOptionMenu () If (self.data = ='') self.setData (); wx.onMenuShareQQ (self.QQData); wx.onMenuShareAppMessage (self.data); wx.onMenuShareTimeline (self.TimeLineData); wx.onMenuShareWeibo (self.WeiBoData);})

Use help:

Var wxshare = require ('wxshare.js')

If the shared content is the same

Wxshare.link ='; wxshare.desc =''; wxshare.imgUrl =''; wxshare.type =''; wxshare.dataUrl =''; wxshare.start ()

If there are inconsistencies, make changes to the inconsistencies

Wxshare.link ='; wxshare.title =''; wxshare.desc ='; wxshare.imgUrl =''; wxshare.setData (); / / must add wxshare.TimeLineData.title =''; wxshare.QQData.desc =''; wxshare.start ()

Key note: setData ()

If all the shared contents are the same, execute start () directly, and determine that the data parameter is empty to true, and setData () will be executed.

Assign values to four shares: QQData data TimeLineData WeiboData, and then initialize

If there is any inconsistency, after the assignment, call setData () directly to assign values to the four parameters, and then modify the corresponding parameters according to the requirements, and initialize them with * start ().

At this point, I believe you have a deeper understanding of "how to encapsulate JS Wechat sharing". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Consistency content parameters encapsulation friends places learning different practical deeper code interest practicality reality sequence idea situation simple operation data method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Xiaomi vpn Huawei