步骤:
(1) 通过设置button的type来进行分享
<button open-type="share" class="btn">分享添加</button>
(2)在页面里面设置参数值,(与method同级)
onAddToFavorites(res) {
// webview 页面返回 webViewUrl
console.log('webViewUrl: ', res.webViewUrl)
return {
title: '自定义标题',
imageUrl: 'http://demo.png',
query: 'name=xxx&age=xxx',
}
}
代码示例:
<button open-type="share" class="btn">分享添加</button>
<script>
export default {
onShareAppMessage(res) {
if (res.from === 'button') {// 来自页面内分享按钮
}
return {
title: '快来一起参与身体体侧吧!',
path:'/pages/add/add' //指定的页面,点击分享的小程序就会显示这个页面
imageUrl:getApp().globalData.baseUrl +"/profile/upload/10/30/Bshare.png"
}
},
data() {
return {
}
},
onLoad() {
},
onShow() {
},
methods: {
}
}
</script>
效果图