h5使用 jssdk微信分享,ios分享内容为空,地址不正确,刷新第二次就正确了

在开发微信h5分享时出现了ios只会在初始化首页的时候进行初始化设置,后面相对个别页面进行特殊化配置的时候,比如跳转链接,图片的修改 在ios上无法生效,但在安卓上是有效的.

原因是:ios是只在进入链接的第一次进行获取 

解决:

vue尽量使用hash模式.

1.分享的js中

newpath = window.entryUrl || newpath = window.location.href.split('#')[0]

export function wechatshare (
  title,
  desc,
  shareimage,
  shareurl,
  path,
  fxstr,
  type,
  issource,
  isfirst,
  iszy,
  scontent
) {
  let newpath = path
  if (window.__wxjs_is_wkwebview === true) {
    newpath = window.location.href.split('#')[0] || window.location.href
    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
      newpath = window.entryUrl
    }
  } else {
    // newpath = window.location.href
    newpath = window.location.href.split('#')[0]
  }
  getJsSign({
    url: newpath
  }).then()
}

2.wxapi.js中   调整newpath

// 获取微信配置
export function getConfig (path, type) {
  let newpath = path
  if (window.__wxjs_is_wkwebview === true) {
    newpath = window.location.href.split('#')[0] || window.location.href
    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
      newpath = window.entryUrl
    }
  } else {
    newpath = window.location.href
  }
  GetwxConfig({ url: newpath }).then()
}

3.router.js路由中

router.afterEach((to, from) => {
  window.document.title = to.meta.title
    ? to.meta.title
    : getStorage('sys_info', {}).appsysname
  if (!window.entryUrl && /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
    var url = window.location.href.split('#')[0]
    window.entryUrl = url // 将后面的参数去除
  }
})

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值