feat(h5): 引入微信JSSDK并实现跨域消息通信
- 在H5环境中动态加载微信JSSDK 实脚本 -现向父窗口发送postMessage消息 - 支持向微信小程序发送postMessage消息 - 添加延迟执行机制确保消息发送时机 - 增强与微信小程序的交互能力
This commit is contained in:
@@ -3,6 +3,12 @@
|
||||
import { ShoproInit } from './sheep';
|
||||
|
||||
onLaunch(() => {
|
||||
// #ifdef H5
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
|
||||
script.type = 'text/javascript';
|
||||
document.body.appendChild(script);
|
||||
// #endif
|
||||
// 隐藏原生导航栏 使用自定义底部导航
|
||||
uni.hideTabBar({
|
||||
fail: () => {},
|
||||
|
||||
@@ -113,6 +113,27 @@
|
||||
|
||||
onLoad((options) => {
|
||||
console.log('🚀 ~ 🐶106 ~ options: ', options);
|
||||
setTimeout(() => {
|
||||
window?.parent?.postMessage(
|
||||
{
|
||||
data: {
|
||||
code: 'success',
|
||||
test: '我是子页面的test!',
|
||||
},
|
||||
},
|
||||
'*',
|
||||
);
|
||||
wx?.miniProgram?.postMessage({
|
||||
data: {
|
||||
action: 'type',
|
||||
message: '1234',
|
||||
timestamp: new Date().getTime(),
|
||||
},
|
||||
});
|
||||
console.log(wx?.miniProgram?.postMessage);
|
||||
console.log(window?.parent);
|
||||
}, 2000);
|
||||
|
||||
if (options?.fileUrl) {
|
||||
isEdit.value = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user