1、Hbuilder中示例:
实际测试有效
<template>
<view>
<!-- 自定义分享按钮,也可不定义,使用小程序设置中自带的分享按钮 -->
<button class="shareBtn" type="default" open-type="share">分享</button>
</view>
</template>
<script>
export default {
onLoad() {
/** 小程序中,转发给朋友按钮设置为可用 */
wx.showShareMenu({
withShareTicket: true,
menus: ["shareAppMessage"]
});
},
methods: {
/** 转发给朋友 */
onShareAppMessage(res) {
return {
title: '自定义标题1',
path: '/pages/index/login' // 当前页面路径
};
},
/** 分享到朋友圈 */
onShareTimeline(res) {
return {
title: '自定义标题2',
path: '/pages/index/login', // 当前页面路径
imageUrl: 'https://i-blog.csdnimg.cn/direct/312a3370b5c643bba6d13f2fd5f0da56.png' // 自定义图像
};
}
},
data() {
return {
param1: true,
account: '',
pwd: ''
}
}
}
</script>
<style>
</style>
2、百度参考文档:
<button class="shareBtn" type="default" data-name="shareBtn" open-type="share">分享</button>