微信分享链接 html,关于vue带hash '#/' 微信分享后点开链接是首页的问题

在调用微信分享api的时候:

let shareUrl = https://xxxx#/abc

wx.onMenuShareTimeline({

title: '',

link: shareUrl,

imgUrl: '',

success:function() {

},

cancel:function() {

}

});

如是这样带有hash的分享后,打开分享后的shareUrl是https://xxxx#/?from=singlemes... 关于from=singlemessage这部分是微信加的。额外 现象是第二次打开就是正常的。

解决方法:

1、将hash分开:将hash前后分开,微信就不会将from=singlemessage拼接到#/abc之后

shareUrl = shareUrl.split('#')[0] + '#' + '/abc'

2、使用url重定向

在static文件夹下,新建html/redirect.html。

redirect.html 内容:

let url = location.href.split('?')

let pars = url[1].split('&')

let data = {}

pars.forEach((n, i) => {

let p = n.split('=')

data[p[0]] = p[1]

})

if (!!data.app3Redirect) {

self.location = decodeURIComponent(data.app3Redirect)

}

然后:

shareUrl = shareUrl.split('#')[0] + 'static/html/redirect.html?app3Redirect=' + encodeURIComponent(shareUrl);

这样就跳转完成

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中实现微信分享链接需要以下步骤: 1. 首先,你需要在微信放平台上注册一个公众号,并获取到对应的AppID。 2. 在Vue项目的入口文件中引入微信JavaScript SDK,可以通过使用`<script>`标签直接引入,或者通过npm安装相关的包。 3. 在需要分享的页面中,可以在`created`或`mounted`钩子中调用微信提供的API,获取当前页面的URL,并配置微信分享所需的参数。例如: ```javascript import wx from 'weixin-js-sdk'; export default { mounted() { this.getWechatConfig(); }, methods: { getWechatConfig() { // 发起请求,获取后端签名 axios.get('/api/getWechatConfig', { params: { url: window.location.href.split('#')[0] } }).then(response => { const { appId, timestamp, nonceStr, signature } = response.data; // 配置微信分享参数 wx.config({ debug: false, // 启调试模式 appId: appId, timestamp: timestamp, nonceStr: nonceStr, signature: signature, jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline'] // 需要使用的API列表 }); wx.ready(() => { // 配置分享给朋友 wx.onMenuShareAppMessage({ title: '分享标题', desc: '分享描述', link: window.location.href, imgUrl: '分享图片链接', success: () => {}, cancel: () => {} }); // 配置分享到朋友圈 wx.onMenuShareTimeline({ title: '分享标题', link: window.location.href, imgUrl: '分享图片链接', success: () => {}, cancel: () => {} }); }); }).catch(error => { console.error(error); }); } } } ``` 4. 最后,通过后端接口获取微信配置信息,其中`url`参数需要替换成当前页面的URL,然后将获取到的配置信息返回给前端。在前端通过微信提供的`wx.config()`方法进行配置,然后在`wx.ready()`方法中配置分享给朋友和分享到朋友圈的行为。 这样,在Vue中实现微信分享链接的功能就完成了。当用户访问分享出去的链接时,会根据配置信息弹出微信分享的对话框,用户可以选择分享给好友或分享到朋友圈。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值