Hbuildx 使用vue打包的App实现微信分享功能

前言:
本文章使用的是vue+h5+plus技术,结合hbuildx打包的App,实现在App中分享页面到朋友圈以及好友。

下面贴码介绍:

<nut-popup v-model="isVisible" position="bottom">
		分享到
		<div class="custom-wrap">
				<div @click="shareWX('WXSceneSession')">
					<img src="@/assets/images/weixin.png" alt="">
					<div>微信</div>
				</div>
				<div style="margin-left:20px;" @click="shareWX('WXSceneTimeline')">
					<img src="@/assets/images/pengyouquan.png" alt="">
					<div>朋友圈</div>
				</div>
		</div>
</nut-popup>

shareWX()这个方法中,如果是分享到好友传值'WXSceneSession'分享到朋友圈传值'WXSceneTimeline'

shareWX(scene){
	let _this=this
	let msg = {
		type: "web",
		thumbs: ['@/assets/images/cxy28.jpg'],
		title:_this.detailHtml.title,
		content:_this.detailHtml.title,
		href: `https://xxxxxxxxxxx/#/detail/${_this.shareDatatype}/${_this.shareDataarticleId}/${_this.shareDataexpertId}/${_this.shareDatastatus}/${_this.shareDatasynMatchId}/${_this.shareDatamatchType}`,
		extra: {
			scene:scene
		}
	}
	let t = this 
	plus.share.getServices(function(e) {
		//在这个数组里 找到属于微信的对象 循环匹配查找
		for (var i in e) {
			if ('weixin' == e[i].id) {
				t.sharewx = e[i] //保存到变量里 (之后即可使用该对象发起分享)
				t.getsend(msg)
			}
		}
	})
}
getsend(msg){
	this.sharewx.send(msg,(res)=>{
		let _t=this
		_t.$toast.success('分享成功');
		_t.isVisible=false //关闭弹框
	},(error)=>{
		this.$toast.fail('分享失败,请重新分享')
	})
}

参数介绍详看share

注意点:
href:分享的链接。【这个参数值不用直接使用window.location.href,因为在App环境中不支持也获取不到,推荐使用链接+拼参形式】

type:分享消息的类型
在这里插入图片描述

thumbs:分享消息的缩略图
title:分享消息的标题
content:分享消息的文字内容

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值