- 先新建一個(gè)js文件,內(nèi)容如下:
//全局點(diǎn)亮所有頁(yè)面的 '分享給朋友' 和 '分享到朋友圈'
export default {
data() {
return {
//設(shè)置默認(rèn)的分享參數(shù)
share: {
//轉(zhuǎn)發(fā)標(biāo)題
title: '',
//轉(zhuǎn)發(fā)路徑
path: '',
//自定義圖片路徑
imageUrl: '',
//自定義頁(yè)面路徑中攜帶的參數(shù)
query: ''
}
}
},
//分享給朋友
onShareAppMessage(res) {
return {
title: this.share.title,
path: this.share.path,
imageUrl: this.share.imageUrl,
success(res) {
console.log(res)
},
fail(res) {
console.log(res)
}
}
},
//分享到朋友圈
onShareTimeline(res) {
return {
title: this.share.title,
query: this.share.query,
imageUrl: this.share.imageUrl,
success(res) {
console.log(res)
},
fail(res) {
console.log(res)
}
}
}
}
- 在main.js中引入
import MyShare from '@/common/myShare.js'//此處為上面的js文件
Vue.mixin(MyShare)
- 完成上面兩步后,每個(gè)頁(yè)面都會(huì)有分享按鈕了,在頁(yè)面的 data 里面可以單獨(dú)設(shè)置參數(shù)了
export default {
data(){
return { //設(shè)置默認(rèn)的分享參數(shù)
share:{
title:'自定義標(biāo)題',
path:'轉(zhuǎn)發(fā)路徑',
imageUrl:'自定義圖片路徑'
}
}
}
}
- 效果圖如下
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-838185.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-838185.html
到了這里,關(guān)于uniapp 微信小程序中實(shí)現(xiàn)“發(fā)送給朋友”和“分享到朋友圈”的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!