天津注冊公司網(wǎng)站宣傳網(wǎng)站怎么做
uniapp實現(xiàn)微信小程序全局【發(fā)送給朋友】、【分享到朋友圈】、【復(fù)制鏈接】
主要使用 Vue.js 的 全局混入
1.創(chuàng)建一個全局分享的js文件。示例文件路徑為:./utils/shareWx.js ,在該文件中定義全局分享的內(nèi)容:
export default {data() {return {}},//分享小程序onShareAppMessage(e) {if (e.from === 'button') {console.log('來自頁面內(nèi)轉(zhuǎn)發(fā)按鈕');} else if (e.from === 'menu') {console.log('右上角菜單轉(zhuǎn)發(fā)按鈕');}return {// 自定義分享內(nèi)容title: 'xxxx',desc: 'xxxxxx',path: '/pages/index/index', // 路徑,可傳遞參數(shù)到指定頁面imageUrl: 'https://xxxxxx.com.cn'};},// 分享到朋友圈onShareTimeline() {return {title: 'xxxxx',path: '/pages/index/index',imageUrl: 'https://xxxxxx.com.cn'};},
}
2.在項目的 main.js 文件中引入該 shareWx.js 文件, 并使用 Vue.mixin() 方法將之全局混入:
// 導(dǎo)入并掛載全局的分享方法