uni-app实现分享功能
2021-09-23 11:02:26
一.局部配置,单个页面
//发送给朋友 onShareAppMessage(){ return { title: '',//分享标题 path: ''//分享页面路径 imageUrl: '',//分享图标 desc:'',//自定义分享描述 } }, //分享朋友圈 onShareTimeline() { },
二.全局配置
1.创建share.js文件
module.exports = { onShow() { let pages = getCurrentPages(); if (pages.length >= 1) { this.$x.pageRouter = (pages[pages.length - 1]).route if(this.$x.pageRouter){ this.$x.mpShare = { title: '', // 分享标题 path: '', // 默认为当前页面路径 imageUrl: '' // 默认为当前页面的截图 } } return ; } }, // 分享到好友 onShareAppMessage(el) { return this.$x.mpShare }, // 分享到朋友圈 onShareTimeline(){ return this.$x.mpShare } }
2.在main.js中引入
// 全局分享 const $x = {}; Vue.prototype.$x = $x; let share=require('common/share.js'); Vue.mixin(share);