首先在全局page.json中添加"shareAppMessage": true
{
"path": "pages/brandCoupon/brandCoupon",
"style": {
"navigationBarTitleText": "霸王餐",
"navigationStyle": "custom",
"enablePullDownRefresh":true,
"shareAppMessage": true
}
},
然后在组件中指定按钮类型为share分享类型
通过v-bind:data-bargainGood绑定并传入给onShareAppMessage分享微信好友后要显示的内容
title表示分享后展示的文本信息
imageUrl表示展示的图片
path表示点击分享的链接要跳转到的页面
<button open-type="share" v-bind:data-bargainGood="{goodsname, spdetailImg,origin_price,refer_price}" class="share">
<view class="discount">邀请帮砍<image
src="https://ebk-picture.oss-cn-hangzhou.aliyuncs.com/mini-wx/images/bargain/share.png"
mode=""></image>
</view>
<view class="mustPrice">最低砍至{{bestPrice}}元</view>
</button>
onShareAppMessage(e) {
console.log(e)
var {goodsname,goodsId, spdetailImg,origin_price,refer_price}=this
// console.log(e.target.dataset,'onShareAppMessage');
let userId = uni.getStorageSync('userInfo').uid
refer_price = '原价'+refer_price/100+'元';
origin_price = '售价'+ origin_price/100+'元'
// let already_grade_amount = '当前'+e.target.dataset.bargaingood.already_grade_amount/100+'元'
return {
title:`${refer_price}, ${origin_price},${goodsname}`,
imageUrl:this.spImgList[0],
path:'pages/bargain/bargainspDetail?uid='+userId+'&goodsId='+goodsId
}
},
展示图