mpShare小程序分享
- 引入uview组件(省略)
- 查看或编辑mpShare.js
module.exports = {
onLoad() {
// 设置默认的转发参数
uni.$u.mpShare = {
title: '', // 默认为小程序名称
path: '', // 默认为当前页面路径
imageUrl: '' // 默认为当前页面的截图
}
},
onShareAppMessage() {
return uni.$u.mpShare
},
// #ifdef MP-WEIXIN
onShareTimeline() {
return this.$u.mpShare
}
// #endif
}
3.在main.js中打开小程序分享功能
// 引入uView对小程序分享的mixin封装
let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare);
- 页面自定义分享标题
在被分享页面的onLoad()函数中自定义标题
onLoad() {
uni.$u.mpShare.title = '天苍苍野茫茫,风吹草低见牛羊';
},