uniapp小程序onShareTimeline()分享朋友圈多参传值
最近在弄uniapp小程序,分享功能传参中遇到了问题,查了很多,作为新手的我也是搞了一会才弄出来。很多资料中的方法,在我这里不生效,最终还是研究出可行的方案。
很多资料中的代码是这样传参:
onShareTimeline(res) {
var query = {
id: 123, //或者 this.id
goodId: 456 // 或者 this.gooodId
}
return {
title: this.goodsInfo.shangpinming,
query: query,
imageUrl: this.goodsInfo.picture,
}
},
但是 我使用这种方法,怎么也接收不到2个参数。于是,我用了下面这种:
onShareTimeline(res) {
//也可以不用声明变量,直接传就行
let id = this.id
let goodId= this.goodId
return {
title: this.goodsInfo.shangpinming,
query: "goodId=" + goodId+"&id=" +id, // "goodId=456&d=123"
imageUrl: this.goodsInfo.picture,
}
},
然后在onLoad 中接收
onLoad(options) {
console.log(options) // {'goodId':456,'id':123}
},
就这样 ok