1.所谓的全局肯定是在main.js中引入你封装好的方法啦
1.1新建js文件share.js,内容如下
export default {
data() {
return {
// 设置默认的分享参数
// 如果页面不设置share,就触发这个默认的分享
share: {
title: 'XXXX',
path: '/pages/home/index',
},
};
},
onShareAppMessage(res) {
var that = this;
return {
title: that.share.title,
path: that.share.path,
success(res) {
uni.showToast({
title: '分享成功',
});
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none',
});
},
};
},
onShareTimeline(res) { // 分享到朋友圈
var that = this;
return {
title: that.share.title,
path: that.share.path,
};
},
};
1.2在main.js中引入
import share from '@/utils/share';
Vue.mixin(share);
1.3在页面中使用(注:如果页面不设置share,就触发默认的分享)
export default {
name: 'PromoteApply',
data() {
return {
// 分享
share: {
title: '推广', //分享的页面标题
path: '/pages/promote/index', //页面路径
},
};
},
}