当前位置:网站首页>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 .
边栏推荐
- Leetcode daily question (1162. as far from land as possible)
- Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
- 编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
- STM32 external interrupt experiment
- Leetcode daily question (2232. minimize result by addressing parents to expression)
- Fundamentals of Electronic Technology (III)__ Chapter 6 combinational logic circuit
- Leetcode daily question (2305. fair distribution of cookies)
- Difference of EOF
- Convert IP address to int
- NR technology -- MIMO
猜你喜欢

UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding

Quelle langue choisir pour programmer un micro - ordinateur à puce unique

Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()

STM32 external interrupt experiment

Characteristics of PUCCH formats

嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走

Hal library sets STM32 clock

Convert IP address to int

UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding

Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
随机推荐
CEF download, compile project
2021-09-26
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
要選擇那種語言為單片機編寫程序呢
编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
Project cost management__ Topic of comprehensive calculation
Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
STM32 serial port usart1 routine
Getting started with shell programming
What do software test engineers do? Pass the technology to test whether there are loopholes in the software program
[CSDN]C1训练题解析_第三部分_JS基础
Error output redirection
Uncle Wang's blog directory [constantly updating]
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门
Flink CDC practice (including practical steps and screenshots)
1922. Count Good Numbers
UCI and data multiplexing are transmitted on Pusch - Part I
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
[22 graduation season] I'm a graduate yo~