In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge about how to realize the function of forwarding friends by WeChat Mini Programs. The content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe you will gain something after reading this article about how to realize the function of forwarding friends by WeChat Mini Programs. Let's take a look.
First, introduce an API:onShareAppMessage (options) of WeChat Mini Programs.
Define the onShareAppMessage function in Page to set the forwarding information for the page.
Only if this event handler is defined, the forward button will be displayed in the upper right-hand menu.
Called when the user clicks the forward button
This event requires an Object for return to customize the forwarded content
Another value is shareTickets, which is successfully forwarded and returned, and it is an array. Each item is a shareTicket, corresponding to a forwarding object.
API talks about this first, and then comes the implementation of forwarding:
The first step is to configure wx.showShareMenu in onLoad
OnLoad: function (e) {wx.showShareMenu ({/ / request Mini Program to return sharing target information withShareTicket: true});}
Then configure onShareAppMessage
/ * forwarding * / onShareAppMessage: function (ops) {if (ops.from = 'button') {/ / from the on-page forwarding button console.log (ops.target)} return {title:' forwarding dom', path: `pages/index/ index`, success: function (res) {/ / forwarding successful console.log ("forwarding success:" + JSON.stringify (res)) Var shareTickets = res.shareTickets; / / if (shareTickets.length = = 0) {/ / return false / / wx.getShareInfo ({/ / shareTicket: shareTickets [0], / / success: function (res) {/ / console.log (res) / /} / /})} can be obtained. Fail: function (res) {/ / forwarding failed console.log ("forwarding failed:" + JSON.stringify (res)) }}}
Let me explain that wx.getShareInfo can get the forwarding details.
The complete js code is
/ / index.js// gets the application instance const app = getApp () Page ({data: {motto: 'Hello World',}, onLoad: function (e) {wx.showShareMenu ({/ / requires Mini Program to return the sharing target information withShareTicket: true}) }, / * forward * / onShareAppMessage: function (ops) {if (ops.from = 'button') {/ / from the forwarding button console.log (ops.target)} return {title:' forward dom', path: `pages/index/ index` Success: function (res) {/ / forwarded console.log ("forwarded successfully:" + JSON.stringify (res)) Var shareTickets = res.shareTickets; / / if (shareTickets.length = = 0) {/ / return false / / wx.getShareInfo ({/ / shareTicket: shareTickets [0], / / success: function (res) {/ / console.log (res) / /} / /})} can be obtained. Fail: function (res) {/ / forwarding failed console.log ("forwarding failed:" + JSON.stringify (res)) })
Smart students should know that the next is wxml code.
Share friends {{motto}}
A friendly reminder that if you click the button to share, button must set open-type= "share" or it won't work.
This is the end of the article on "how to achieve the function of forwarding friends by WeChat Mini Programs". Thank you for your reading. I believe that everyone has a certain understanding of the knowledge of "how to realize the function of WeChat Mini Programs forwarding friends". If you want to learn more knowledge, you are welcome to follow 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.