安装微信SDK
npm i weixin-js-sdk -D
页面使用
import wx from 'weixin-js-sdk'
webView内H5判断代码
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
//ios的ua中无miniProgram,但都有MicroMessenger(表示是微信浏览器)
wx.miniProgram.getEnv((res)=>{
if (res.miniprogram) {
this.$edd("在小程序里");
wx.config({
// debug: true, // 调试时可开启
appId: '小程序 AppID', // <!-- replace -->
timestamp: 0, // 必填,填任意数字即可
nonceStr: 'nonceStr', // 必填,填任意非空字符串即可
signature: 'signature', // 必填,填任意非空字符串即可
jsApiList: ['chooseImage'], // 必填,随意一个接口即可
openTagList:['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
})
} else {
this.$edd("不在小程序里");
}
})
}else{
this.$edd('不在微信里');
}
//判断是否在ios端
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
setTimeout(_=>{
// if(document.getElementsByTagName('html').classList.contains('minsoft')){
let html = document.getElementsByTagName('html')[0]
if(html.className == 'minsoft'){
// console.log(html.className)
// this.$edd(html.className)
// this.$edd(...document.getElementsByTagName('html'))
// this.$forceUpdate()
// this.$router.replace('/my')
// setTimeout(_=>{
// this.$router.replace('/home')
// },50)
}
},50)
}