微信小程序分享API `onShareAppMessage` 带的参数只能叫`id`,不能叫其他的,不然拿不到。
使用时可以在单页面使用,也可以使用全局混入,一般来说我们都使用全局混入的方式去做。
注意,这个函数是一个页面钩子函数,需要与onLoad等函数同级。
使用示例:
//share.mixin.js
export default {
data() {
return {
share: {
title: '你的标题',
path: '/pages/index/index',
imageUrl: '',
desc: '',
}
}
},
onShareAppMessage(res) {
return {
//标题
title: this.share.title,
//页面路径
path: this.share.path,
//分享后显示的图片的地址,默认为当前页面的截图
imageUrl: this.share.imageUrl,
//描述
desc: this.share.desc,
//内容
content: this.share.content,
success(res) {
uni.showToast({
tit