当前位置:网站首页>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 .
边栏推荐
- Directory and switching operation in file system
- STM32 serial communication principle
- Nr-prach: access scenario and access process
- 307. Range Sum Query - Mutable
- Convert IP address to int
- 【順利畢業】[1]-遊覽 [學生管理信息系統]
- UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
- IDEA远程断点调试jar包项目
- Jetson nano custom boot icon kernel logo CBOOT logo
- Project cost management__ Topic of comprehensive calculation
猜你喜欢

Difference of EOF
![[CSDN]C1训练题解析_第二部分_Web基础](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[CSDN]C1训练题解析_第二部分_Web基础

Leetcode daily question (931. minimum falling path sum)

内存数据库究竟是如何发挥内存优势的?

【22毕业季】我是毕业生yo~

STM32 port multiplexing and remapping

Nr-prach:prach format and time-frequency domain

单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇

STM32 external interrupt experiment

Vector processor 9_ Basic multilevel interconnection network
随机推荐
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
Desktop icon recognition based on OpenCV
Construction and test of TFTP server under unbuntu (Debian)
MySQL的简单使用(增删改查)
Matlab reads hexadecimal numbers and converts them into signed short
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
Design and development of biological instruments
QT qcombobox QSS style settings
Project cost management__ Cost management technology__ Article 8 performance review
Leetcode daily question (1162. as far from land as possible)
CEF download, compile project
Difference of EOF
MySQL 数据库基础知识(系统化一篇入门)
Equality judgment of long type
Process communication - semaphore
IDEA远程断点调试jar包项目
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
顺利毕业[2]-学生健康管理系统 功能开发中。。。
开学实验里要用到mysql,忘记基本的select语句怎么玩啦?补救来啦~
[CSDN]C1训练题解析_第三部分_JS基础