当前位置:网站首页>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();
}
})
边栏推荐
- Today is important
- [globally unique ID] how to handle the ID primary key after dividing the database and table?
- Idea2021 installation
- China trifluoroethanol industry research and investment forecast report (2022 Edition)
- STM32 Development Notes 119: what macros are required to enable FPU?
- 阿亚的角度思考
- 深入掌握Service
- Learn to use PHP to get the URL address link after resetting
- Perspective
- Burpsuite爆破之token值替换
猜你喜欢

教你三招从让性能从20s优化到500ms

Gradle test and idea test

Paper:《Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Condi

OA and fansoft Bi cross system users, departments and posts synchronous summary

2、 Mysql database foundation
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]
![Introduction to fundamentals of operations research [1]](/img/79/b613bff74a78ad63f202b9e652220d.png)
Introduction to fundamentals of operations research [1]

MCU experiment record

Interview required: how to design the seckill system?

推荐系统-协同过滤在Spark中的实现
随机推荐
Druid connection pool - strong self-study from 0. Those who don't understand Druid can click in. If you know not to click in, you will think I'm wordy
市场的调节
Thinking from the perspective of Aya
IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…
PyG搭建GCN实现链接预测
How to publish your own NPM package
Pychart configuration pyqt5
Json.tojsonstring cannot pass Boolean
深入掌握Service
MCU experiment record
How to ensure data consistency between MySQL and redis?
Detailed explanation of security authentication of mongodb
很清晰的条理
Web: compiling big refactoring from 10 to 1
ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
Gradle test and idea test
Gbase 8A about no suitable driver
Data link layer protocol -- Ethernet protocol
Etcd learning
Docker builds MySQL master-slave replication