赞
踩
uniapp
https://zh.uniapp.dcloud.io/api/plugins/share.html#onshareappmessage
export default {
onShareAppMessage(res) {
if (res.from === 'button') {// 来自页面内分享按钮
console.log(res.target)
}
return {
title: '自定义分享标题',
path: '/pages/test/test?id=123'
}
}
}
需要再真机上看具体效果(以下是我的代码)
utils页面(封装起来了)
function share(image, title = "你好呀", path = this.getCurrentPageUrlWithArgs()) { if (!image) { image = "https://static.taidoukeji.cn/wxchat/yww/oilBgc.jpg" } return { title: title, path: path, imageUrl: image } } function shareApplets(image, title = "你好呀", path = this.getCurrentPageUrlWithArgs()) { if (!image) { image = "https://static.taidoukeji.cn/wxchat/yww/oilBgc.jpg" } return { title: title, query: path, imageUrl: image } } function getCurrentPageUrlWithArgs(defUrl = null) { var pages = getCurrentPages() //获取加载的页面 var currentPage = pages[pages.length - 1] //获取当前页面的对象 var url = "/" + currentPage.route //当前页面url if (defUrl) url = defUrl; var options = currentPage.options //如果要获取url中所带的参数可以查看option if (getApp().globalData.memberId) { options.shareId = getApp().globalData.memberId } //拼接url的参数 var urlWithArgs = url + "?" for (var key in options) { var value = options[key] urlWithArgs += key + "=" + value + "&" } urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1) return urlWithArgs } export default { getCurrentPageUrlWithArgs, share, shareApplets }
需要使用页面
onShareAppMessage() {
return this.$utils.share('https://static.taidoukeji.cn/wxchat/yww/oilBgc.jpg?', "您的好友邀请您优惠加油啦!")
},
//获取你的昵称getApp().globalData.userInfo.nickName
// onShareAppMessage() {
// return this.$utils.share('https://static.taidoukeji.cn/wxchat/yww/oilBgc.jpg?', "您的好友" + getApp().globalData.userInfo.nickName + "邀请您优惠加油啦!")
// },
onShareTimeline(){
return this.$utils.shareApplets();
},
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。