onLoad(){},
// 1.发送给朋友
onShareAppMessage(res) {
console.log("res",res);
console.log("page",uni.$u.page());
if (res.from === 'button') {// 来自页面内分享按钮
return {
title: '首页',
path: '/pages/home/home',
imageUrl: this.share.image,
}
}
return {
title: '首页',
path: '/pages/home/home',
imageUrl: this.share.image|| '',
}
},
//2.分享到朋友圈
onShareTimeline(res) {
console.log("this.share.path",this.share.path);
return {
title: this.share.title,
path: this.share.path || '/pages/home/home',
imageUrl: this.share.image|| '',
}
},
uview全局分享地址:https://uviewui.com/js/mpShare.html
// minxin文件 '@/utils/share.js'
export default {
data() {
return {
// 默认的全局分享内容
share: {
title: '',
path: '', // 全局分享的路径,比如 首页
image: '', // 全局分享的图片(可本地可网络)
}
}
},
// 定义全局分享
// 1.发送给朋友
onShareAppMessage(res) {
console.log("res",res);
console.log("page",uni.$u.page());
if (res.from === 'button') {// 来自页面内分享按钮
return {
title: this.share.title,
path: this.share.path || '/pages/home/home',
imageUrl: this.share.image,
}
}
return {
title: this.share.title,
path: this.share.path || '/pages/home/home',
imageUrl: this.share.image|| '',
}
},
//2.分享到朋友圈
onShareTimeline(res) {
console.log("this.share.path",this.share.path);
return {
title: this.share.title,
path: this.share.path || '/pages/home/home',
imageUrl: this.share.image|| '',
}
},
methods: {
setGlobalValue(value) {
this.share = value;
},
getGlobalValue() {
return this.share;
}
}
}
import share from '@/utils/share.js'
Vue.mixin(share)
<button class="share_style" open-type="share">分享</button>
如果分享页使用了自定义导航栏,分享路径后面加个参数判断,分享打开的页面获取参数,自定义按钮跳转到首页即可
this.setGlobalValue({
title: '分享名称',
path: `/pages/detail/detail?id=${this.id}`,
image:'分享图片'
})