WeChat H5 about obtaining WeChat JSDK (uniapp)
- Compatibility of the built-in environment of Android and IOS browsers
- Compile and configure the choice of Hash and History mode
- Configuration Demo example
hash will carry#
改变#号后面的内容时,不会重新加载的,会新增访问历史记录。
History will not carry #(Obsessive-compulsive disorder-.-)
直接重载页面以及各类奇特问题:跳转页面白屏闪烁、无法返回、返回、等
//拟化描述
/*
1.进入微信公众号配置的站点页面,需要使用相关的JSDK配置Config信息来协助我们同微信Api的交互
2.开门需要一把钥匙(访问页面路径的完整地址且符合使用规范的网址)->官方文档
*/
/*
IOS:进入站点的首个页面!!!!(首个页面路径)
*/
/*
Android:以当前访问页面地址即可
*/
//进入站点执行的一次业务-保持本次业务闭环的有效性
const IOSUrl = window.location.href;
//微信JSDK配置
WxConfig:async function(status){
//配置验证是否为微信内置H5环境
//let IsWeChat = await WxApi.VerifyClient();
//if(IsWeChat=="nowx") return console.log(IsWeChat,"非微信客户端-禁止使用WxConfig方法");
let Local = "";
if(/(Android)/i.test(navigator.userAgent)){
Local = encodeURIComponent(window.location.href.split('#')[0]);
}else{
Local = encodeURIComponent(IOSUrl);
}
let res = await this.HttpGet("you get url?path="+Local);
if(res.ret==1){
}
else{
return false}
}
/*
方法调用,可以放置在公告方法的位置或是单独的页面需求,来处理业务逻辑
*/
Official document: WeChat development document (WeChat H5)
The specific use of JSDK : official JSDK usage document
Summary: The
value is valid, but due to different environments, it may be unusable in the current environment.
If you don’t understand, you can leave a message.