Said WeChat sharing, quite pit, first docking, thought can be like the app end, through his written actionSheet to share, then read carefully, found that the share is called WeChat myself to share more the top right corner, if you don’t write, is not contain in the upper right corner of the three little WeChat sharing, that is, It’s in grandma’s arms. And the latest official notice, abandoned part of the interface, but actually, your jsApiList if you do not write those two abandoned, will still report an error, may be a semi-paralyzed state.

Our code was written in last time’s Wechat. Js. Just add a little bit of wechat to share things, signature or use initJssdk method, please see:

import { getWxConfig } from 'api/index/index.js'; import { wxPay } from 'api/index/index.js'; Import wx from 'weixin-js-sdk' export default {// check whether isWechat: function() { var ua = window.navigator.userAgent.toLowerCase(); If (ua.match(/micromessenger/ I) == 'micromessenger') {// console.log(' wechat client ') return true; } else {// console.log(' not wechat client ') return false; InitJssdk: function(callback, url) {console.log(url) // server to sign let data = {url: encodeURIComponent(url) } getWxConfig(data).then(res => { if (res.status == 1000) { if (res.data) { wx.config({ debug: false, appId: res.data.appId, timestamp: res.data.timestamp, nonceStr: res.data.nonceStr, signature: Res.data.signature, // Add the interface name jsApiList to the shared apilist: [ 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'updateAppMessageShareData', 'updateTimelineShareData' ] }); If (callback) {callback(res.data); }}}}). Catch (err => {})}, //this.$wechat. Share (data,url) Function (data, url) {//data is the content we passed to share. // Url is the current page path url = url? url : window.location.href.split('#')[0]; This.initjssdk (function(callback) {wx.ready(function() {var shareObject = {title: Data. title,//// Share title desc: data.des,//// Share Description Link: data.url,// Share link. The domain name or path of the link must be the same as the public id JS security domain name corresponding to the current page imgUrl: Function (res) {cancel: function(res) {this. toast({icon: 'none', title: 'share failed! ', duration: 1000 }) } }; / / share with friends and share to QQ wx. UpdateAppMessageShareData (shareObject); / / share to friends and share to QQ space wx. UpdateTimelineShareData (shareObject); }); }, url); }},Copy the code

After we look at the code, we will find that sharing is actually those operations, wechat configuration, signature. The share interface is then invoked. We just need to understand its API rules, and that’s not a problem. Friendly note: look at the comments in the code, haha. In this way, our wechat sharing is completed. In view of the fact that it can only be used in the wechat environment, I think it is really not meaningful. If the company has the conditions, it is best to find a strong third party to docking H5 sharing. Or you can share it in each major browser and share it on multiple platforms, haha. Code text is not easy, hope you give a praise! Thank you very much! I hope it helps