#小程序# 如何分享小程序到群聊或者朋友?

微信文档--小程序分享https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareAppMessage-Object-objecthttps://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareAppMessage-Object-object

步骤:

(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>

效果图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值