当前位置:网站首页>Forwarding and sharing function of wechat applet
Forwarding and sharing function of wechat applet
2022-07-25 04:58:00 【richest_ qi】
List of articles
The forwarding and sharing function of wechat applet , There are two ways to do it :
- button Components
open-type="share", After clicking the button , Will triggerPage.onShareAppMessageevent . - Menu in the upper right corner of the page “ forward ” Button , After clicking the button , It will also trigger
Page.onShareAppMessageevent .
button Component's open-type=“share”
The files involved in the code are :
- app.json
- pages/about/about.wxml
- pages/about/about.wxss
- pages/about/about.js

button Components open-type="share", Click this button , Trigger Page.onShareAppMessage event .
app.json
{
"pages": [
"pages/about/about"
],
"window": {
"navigationBarBackgroundColor": "#0149af",
"navigationBarTitleText": " home page ",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/about/about.wxml
<view class="aboutContainer">
<view class="content"> What kind of people are geeks ? They are as wise as fools and full of scientific spirit , Natural aversion to all common sense things ; They are born to love exploration and creation , I hate following and following others ; They have their own way , Never set a restricted area for yourself ; They believe in freedom , He disdains artificial restrictions and is keen to challenge authority ; In their work, they advocate reducing complexity to simplicity , Believe in the power of design and pursue product aesthetics ……</view>
<button open-type="share"> Click me to share </button>
</view>
pages/about/about.wxss
.content{
margin: 10rpx;
padding: 10rpx;
text-align: justify;
line-height: 40rpx;
background:#eee;
color: #1a74f1;
font-size: 24rpx;
border-radius: 10rpx;
margin-bottom: 10rpx;
}
pages/about/about.js
Page({
})
The forward button in the upper right corner of the page
First , Only defined onShareAppMessage(), The menu in the upper right corner of the page will display “ forward ” Button .
then ,onShareAppMessage(Object object) Receive an object as a parameter , This object contains the following properties :
from, Forward event source ,string type , There are two values :"button", By clicking button Component forwarding ."menu", Forward by clicking the forward menu in the upper right corner of the page .
target, It's an object .- If
fromyes"button", betargetThis forwarding event is triggered button Components . - If
fromyes"menu", betargetyesundefined.
- If
Last ,onShareAppMessage(Object object) You can return an object , Used to customize the forwarding content . The returned object can contain the following properties :
title, Forward title , The default is the name of the current applet .path, Forwarding path , Must be based on/Full path at the beginning , The default is the current page path.imageUrl, Custom image path , It can be a local picture , You can also network pictures , The default is a snapshot of the current page .
The main files involved in the code are :
- app.json
- pages/about/about.wxml
- pages/about/about.wxss
- pages/about/about.js
- pages/home/home.wxml
- pages/home/home.wxss
- pages/home/home.js

app.json
{
"pages": [
"pages/about/about",
"pages/home/home"
],
"window": {
"navigationBarBackgroundColor": "#0149af",
"navigationBarTitleText": " home page ",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/about/about.wxml
<view class="aboutContainer">
<view class="content"> What kind of people are geeks ? They are as wise as fools and full of scientific spirit , Natural aversion to all common sense things ; They are born to love exploration and creation , I hate following and following others ; They have their own way , Never set a restricted area for yourself ; They believe in freedom , He disdains artificial restrictions and is keen to challenge authority ; In their work, they advocate reducing complexity to simplicity , Believe in the power of design and pursue product aesthetics ……</view>
<button open-type="share" id="share-btn"> Click me to share </button>
</view>
pages/about/about.wxss
.content{
margin: 10rpx;
padding: 10rpx;
text-align: justify;
line-height: 40rpx;
background:#eee;
color: #1a74f1;
font-size: 24rpx;
border-radius: 10rpx;
margin-bottom: 10rpx;
}
pages/about/about.js
Page({
onShareAppMessage({
from,target}){
console.log(from,target);
let myObj = {
title:` come from ${
from} Forwarding ,AITO Invite you to test drive `,
path:"/pages/home/home",
imageUrl:"/static/images/car.jpg"
}
return myObj;
}
})
pages/home/home.wxml
<view class="homeContainer">
<view class="content" wx:for="{
{contentList}}" wx:key="{
{index}}">{
{item}}</view>
</view>
pages/home/home.wxss
.homeContainer{
padding: 20rpx;
}
.content{
width: 100%;
height: 600rpx;
line-height: 600rpx;
text-align: center;
background:#eee;
color: #1a74f1;
font-size: 64rpx;
border-radius: 10rpx;
margin-bottom: 10rpx;
}
pages/home/home.js
Page({
data:{
contentList:[]
},
onLoad(){
const contentList = this.getDataFromServer();
this.setData({
contentList});
},
getDataFromServer(){
let result = [" KFC house express "," Sea of clouds food "," Xibei youmian village "," East slope of Meizhou "," Wallace "];
return result;
},
onReachBottom(){
console.log("on reach bottom");
console.log(" Pull up and touch the bottom , Get the data and append it to the list ");
const appendData = [" other "," other "," other "," other "," other "];
const newContentList = [...this.data.contentList,...appendData];
this.setData({
contentList:newContentList});
},
onPullDownRefresh(){
console.log("on pull down refresh");
console.log(" The drop-down refresh , Get the latest list data ");
this.getDataFromServer();
}
})
边栏推荐
- 956. Highest billboard pressure DP
- 2022-7-18 summary
- Token value replacement of burpsuite blasting
- Compile ue5.0
- mitt.js:小型事件发布订阅库
- [live review] AI customer service "changes according to the situation", and man-machine dialogue can be easier
- STM32 Development Notes 119: what macros are required to enable FPU?
- [no title] 1
- Pychart configuration pyqt5
- ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
猜你喜欢
![[no title] 1](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[no title] 1

Web: compiling big refactoring from 10 to 1

Unity LOD

Now the operator wants to check the answer details of all user questions from Zhejiang University. Please take out the corresponding data

How to ensure data consistency between MySQL and redis?
![[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术](/img/32/2da78bd5866cfab9ee64dfcb1c1204.png)
[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术

I didn't expect Mysql to ask these questions

Token value replacement of burpsuite blasting

IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…

ThreadLocal Kills 11 consecutive questions
随机推荐
Getting started with scratch
Baklib: share some methods about building enterprise knowledge management (km)
今天很重要
Interpretation and download of the report | ink Tianlun July database industry report, be prepared for danger in times of safety, and safety first
Valley p2420 let's XOR solution
Burpsuite爆破之token值替换
2022-7-15 summary
[literature notes] pointmlp
Construction of Seata multilingual system
二、MySQL数据库基础
Chart is code: build a new generation of graphics library in a coded way -- feekin
Open source summer interview | "after 00" PMC member Bai Zeping
[live review] AI customer service "changes according to the situation", and man-machine dialogue can be easier
Leetcode55. Jumping game
Gbase 8A about no suitable driver
# 1. Excel的IF函数
I didn't expect Mysql to ask these questions
Novel capture practice
ES6 -- Methods and extensions of array objects, traversal of arrays, and extension methods of strings
Dark king | analysis of zego low illumination image enhancement technology