全局分享
App({
onShareAppMessage() {
wx.onAppRoute(() => {
console.log('當(dāng)前頁(yè)面路由發(fā)生變化 觸發(fā)該事件onShareAppMessage')
const pages = getCurrentPages() //獲取加載的頁(yè)面
const view = pages[pages.length - 1] //獲取當(dāng)前頁(yè)面的對(duì)象
//需要單獨(dú)寫分享方法的頁(yè)面
let noGlobalSharePages = ["pages/index/messageDetail/messageDetail", "pages/worker/workerInfo/workerInfo"]
//如果頁(yè)面路由屬于單獨(dú)分享數(shù)組里面的頁(yè)面,則return
if (noGlobalSharePages.includes(view.route)) return;
if (!view) return false //如果不存在頁(yè)面對(duì)象 則返回
view.onShareAppMessage = () => { //重寫分享配置
return {
title: '全局分享頁(yè)面~',
imageUrl: 'image_path',
path: '/pages/index/index' //點(diǎn)擊分享鏈接進(jìn)入指定頁(yè)面
}
}
})
},
onLaunch() {
this.onShareAppMessage()
}
})
單獨(dú)分享
例如:這個(gè)頁(yè)面:pages/index/messageDetail/messageDetail文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-585870.html
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function () {
return {
title: '單頁(yè)面分享',
path: 'pages/worker/workerInfo/workerInfo?id='+this.data.id // 路徑,傳遞參數(shù)到指定頁(yè)面。
}
}
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-585870.html
到了這里,關(guān)于【微信小程序】全局分享和頁(yè)面分享的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!