export default {
data() {
return {
//这个share可以在每个页面的data中设置相应的转发内容
share: {
title: '分享有礼',
path: '/pages/index/index',
}
}
},
onShareAppMessage(res) {
var userId = uni.getStorageSync('shareUserId');
if (userId) this.share.path = '/pages/index/index?parentId=' + parseInt(userId);
console.log(this.share.path)
return {
title: this.share.title,
path: this.share.path,
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none'
})
}
}
},
onShareTimeline(res) {
var parent_Id = 0;
var userId = uni.getStorageSync('shareUserId');
if (userId) parent_Id = parseInt(userId);
console.log(this.share.path)
return {
title: this.share.title,
query: 'parentId='+parent_Id
}
}
}
1.保存文件share.js
2.在main.js中全局引用
// #ifdef MP-WEIXIN
import share from '@/share.js';
Vue.mixin(share)
// #endif