当前位置:网站首页>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 .
边栏推荐
- Project cost management__ Cost management technology__ Article 8 performance review
- STM32 serial communication principle
- Flink learning notes (10) Flink fault tolerance mechanism
- Analysis of the implementation principle of an open source markdown to rich text editor
- Flink CDC practice (including practical steps and screenshots)
- Leetcode daily question (1162. as far from land as possible)
- Directory and switching operation in file system
- Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
- 应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
- Electronic product design
猜你喜欢

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

The cyclic shift of PUCCH in NR channel is generated by MATLAB

Leetcode daily question (931. minimum falling path sum)

Project cost management__ Topic of comprehensive calculation

uniapp 实现微信小程序全局分享及自定义分享按钮样式

Stm32-hal library learning, using cubemx to generate program framework

GPIO port details, Hal library operation keys

UCI and data multiplexing are transmitted on Pusch - Part I

Shell logic case

Definition and use of enum in C language
随机推荐
UCI and data multiplexing are transmitted on Pusch - determine the bit number of harqack, csi1 and csi2 (Part II)
[CSDN]C1訓練題解析_第三部分_JS基礎
Chromium Embedded Framework (CEF) 介绍
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
Nr--- Pusch I: sorting out the agreement process
【22毕业季】我是毕业生yo~
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 3 --blinker_ MIOT_ Light (lighting technology app control + Xiaoai classmate control)
Stm32-hal library learning, using cubemx to generate program framework
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
Introduction to chromium embedded framework (CEF)
How does the nr-prach receiver detect the relationship between prembleid and Ta
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
[CSDN]C1训练题解析_第四部分_Web进阶
内存数据库究竟是如何发挥内存优势的?
How MySQL modifies null to not null
1300. sum of varied array closed to target