App.vue文件进行重写主要是loadEWechatSdk()方法的使用

<template><App :keepAliveInclude="keepAliveInclude"/></template><script>
export default {
  onLaunch() {
    console.log('App Launch')

    // 记录应用入口地址
    this.storageEntryUrl()

    // 加载企业微信SDK配置
    // TODO 是否根据各部署省市个性化配置判断是否加载
    this.loadEWechatSdk()
  },
  onShow() {
    console.log('App Show')

  },
  onHide() {
    console.log('App Hide')
  },
  methods: {
    storageEntryUrl() {
      const firstEntryUrl = window.location.href.split("#")[0];
      window.sessionStorage.setItem('firstEntryUrl', firstEntryUrl)
      console.info('记录firstEntryUrl: ', firstEntryUrl)
    },
    loadEWechatSdk() {
      // H5:手动加载 js-sdk 重写覆盖掉 uni 自带的 window.wx
      window.wx = null
      const script1 = document.createElement('script')
      script1.referrerpolicy = "origin"
      script1.src = 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js'
      document.head.appendChild(script1)
      script1.onload = () => {
        const script2 = document.createElement('script')
        script2.referrerpolicy = "origin"
        script2.src = 'https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js'
        document.head.appendChild(script2)
        script2.onload = () => {
          console.info('完成手动加载 js-sdk 重写覆盖掉 uni 自带的 window.wx')
        }
      }
    },
  }
}
</script>

<style>

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐