uni-app调用小程序覆盖原uni-app框架window.wx
App.vue文件进行重写主要是loadEWechatSdk()方法的使用。
·
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>
更多推荐
已为社区贡献6条内容
所有评论(0)