Put this code in the link to go to the page for example (share page page login share link is index, put this code in the index page)
Put this code in mounted
The function getQueryString (name) {/ / according to the field to see if the url splicing & string var reg = new RegExp (" (^ | &) "+ name +" = (/ ^ & *) (& | $) ", "I"); var r = window.location.search.substr(1).match(reg); if (r ! = null) return unescape(r[2]); return null; } var from = getQueryString("from"); var appinstall = getQueryString("appinstall"); var sec = getQueryString("sec"); var timekey = getQueryString("timekey"); If (the from | | appinstall | | the SEC | | timekey) {/ / if the stitching on the var shareUrl = "http://badminton.mohennet.xyz/index/" window.location.href=shareUrl; }Copy the code
Introduced in the share page
import wx from "weixin-js-sdk";
Copy the code
If no, enter the command line
npm install weixin-js-sdk --save-dev
Copy the code
Reference the code in the Mounted function
WXshare() {console.log(" share "); var that = this; var shareUrl = "http://xxxxxx.xyz/index/"; var url=shareUrl.split('#')[0] var imgUrl = "https://image--ccccc.oss-cn-hangzhou.aliyuncs.com/publish/share.jpg"; (that.cindex = this.$route.query.cindex), (that.remain = 5 - this.$route.query.cindex); that.axios.get("http://xxxxx.xyz/sign_data").then(res => { console.log(res); var nonceStr = res.data.nonceStr; var timestamp = res.data.timestamp; var signature = res.data.signature; Wx. config({debug: false, // Enable the debug mode, the return value of all API calls will be alert in the client, to view the passed parameters, can be opened in the PC, parameter information will be printed in the log, only on the PC. Timestamp: timestamp, // Required, generated signature's timestamp nonceStr: NonceStr, // Required, generate a random string of signatures signature: signature, // Required, signature, see Appendix 1 jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "translateVoice"] // Mandatory, list of JS interfaces to be used, see Appendix 2 for the list of all JS interfaces); Wx. onMenuShareAppMessage({title: "challenge the world champion, win 10 yuan phone fee ", // share title desc:" Faster than fuxing shuttlecock, can you catch?" Split ('#')[0], // imgUrl: imgUrl, // Share icon type: "Link ", // Share type,music, video or link, leave blank default link dataUrl: "", // If type is music or video, provide data link, default blank success: function(res) { console.log(window.location.href.split('#')[0]) console.log(res); Showshare = false; // The callback function that is executed after the user confirms the share. Share the console. The log (" 1 "); }, cancel: function() {console.log(" share 2"); // callback function executed after user unshares}}); Wx. onMenuShareTimeline({title: "Challenge the world champion, win 10 yuan phone fee ", // share the title desc:" Faster than fuxing badminton, can you catch it?" Link: url.split('#')[0], imgUrl: imgUrl, // Share icon success: The function () {the console. The log (window. The location. The href. Split (' # ') [0]) console. The log (" share 1 "); Showshare = false; // The callback function that is executed after the user confirms the share. }, cancel: function() {console.log(" share 2"); // callback function executed after user unshares}}); }); }Copy the code