当前位置:网站首页>Uniapp realizes global sharing of wechat applet and custom sharing button style
Uniapp realizes global sharing of wechat applet and custom sharing button style
2022-07-03 09:51:00 【drhrht】
uniapp Realize the global function of wechat applet Forward to friends / Share with friends The function of . The main use of Vue.js Of The whole thing is in Concept .
Directly up below Implementation steps and code :
Create a global shared content file
1. Create a globally shared js file . The sample file path is :@/common/share.js , Define global shared content in this file :
export default {
data() {
return {
// Default global shared content
share: {
title: ' Title of global sharing ',
path: '/pages/home/home', // Global shared path , such as home page
imageUrl: '/static/imgs/fenxiang-img.png', // Globally shared pictures ( Can be local or network )
}
}
},
// Define global sharing
// 1. Send it to a friend
onShareAppMessage(res) {
return {
title: this.share.title,
path: this.share.path,
imageUrl: this.share.imageUrl,
}
},
//2. Share with friends
onShareTimeline(res) {
return {
title: this.share.title,
path: this.share.path,
imageUrl: this.share.imageUrl,
}
},
}
Import and register the file globally
2. stay Project main.js The document introduces the share.js File and use Vue.mixin() Method to globally mix it into :
// Import and mount the global sharing method
import share from '@/common/share.js'
Vue.mixin(share)
Let's take a look at the overall sharing effect :


Custom page sharing content
3. If in a particular The page needs to customize the shared content , You can still use the... Of the page onShareAppMessage() and onShareTimeline() Method to customize the shared content , The global sharing will be overwritten by the sharing content defined on the page . Examples are as follows :
onLoad() {},
// Customize the forwarding of this page to friends ( There are already global sharing methods , The global... Will be overwritten here )
onShareAppMessage(res) {
return {
title: ' Title of page sharing ',
path: '/pages/my/my',
imageUrl: '/static/imgs/mylogo.png'
}
},
// Share the custom page to the circle of friends
onShareTimeline(res) {
return {
title: ' Title of page sharing ',
path: '/pages/my/my',
imageUrl: '/static/imgs/mylogo.png'
}
},
notes :onShareAppMessage() and onShareTimeline() The way is and onLoad ,methods Equivalent method Of .
Realize the effect of custom sharing button style
Effect display :


analysis : The above two styles are common wechat applet sharing button custom styles , However, in reality, we are not right Button for such a custom style , But to make such a style On or directly a image picture , But to realize that clicking it triggers sharing , We just need to cover it with Button , Of course, this button is used to trigger our sharing function , And we just need to make it completely transparent , Such a combination , Our effect is like realizing the customization of the sharing button . The sample code is as follows :
1.HTML The code is as follows
<!-- One click sharing -->
<view class="share">
<u-image src="/static/imgs/yjfx.png" width="110" height="110"></u-image>
<u-button id="shareBtn" open-type="share" ></u-button>
</view>
2.CSS The code is as follows ( What we use here is SCSS Writing )
.share {
width: 110rpx;
height: 110rpx;
border-radius: 50%;
position: absolute;
top: 50%;
right: 29rpx;
#shareBtn {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
}
So we can achieve “ Custom share button ” The effect has been achieved. , The core is to put a share button above our custom style area , Let the share button completely cover it and make the share button completely transparent .
边栏推荐
- 2021-09-26
- Leetcode daily question (1024. video sticking)
- NR technology -- MIMO
- Make the most basic root file system of Jetson nano and mount NFS file system on the server
- Epollet lessons
- Leetcode daily question (2109. adding spaces to a string)
- Leetcode daily question (2232. minimize result by addressing parents to expression)
- Leetcode daily question (2090. K radius subarray averages)
- Nr-prach: access scenario and access process
- Stm32-hal library learning, using cubemx to generate program framework
猜你喜欢

Development of electrical fire system

Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
![[CSDN] C1 training problem analysis_ Part III_ JS Foundation](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[CSDN] C1 training problem analysis_ Part III_ JS Foundation

Difference of EOF

Mysql database underlying foundation column

Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?

【男保姆式】教你打开第一个微信小程序

当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学

对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门

Leetcode daily question (1162. as far from land as possible)
随机推荐
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
我想各位朋友都应该知道学习的基本规律就是:从易到难
QT qcombobox QSS style settings
Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle
Flink learning notes (IX) status programming
Install local sources using yum
Nr-prach:prach format and time-frequency domain
STM32 serial communication principle
Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5
Convert IP address to int
Analysis of the implementation principle of an open source markdown to rich text editor
Vector processor 9_ Basic multilevel interconnection network
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
All processes of top ten management in project management
Stm32-hal library learning, using cubemx to generate program framework
Development of fire evacuation system
NR PUCCH format0 sequence generation and detection mechanism
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
Jetson nano custom boot icon kernel logo CBOOT logo