非常可乐
非常可乐
  • 发布:2022-09-13 22:45
  • 更新:2022-09-13 22:45
  • 阅读:720

uniapp 与webview传参 uni.webview.1.5.4.js

分类:uni-app

版本
uni.webview.1.5.4.js 版本 1.5.4
https://uniapp.dcloud.net.cn/component/web-view.html#
https://gitee.com/dcloud/uni-app/raw/dev/dist/uni.webview.1.5.4.js

传参:
vue中。监听。
可以写在app.vue中。需要用的地方监听。

// #ifdef APP-PLUS  
            //  app 用于监听 验证码webview 事件  
            plus.globalEvent.addEventListener('plusMessage', (msg) => {  
                const result = msg.data.args.data;  
                if(result.name == 'postMessage'){  
                    console.log('postMessage', msg)  
                    uni.$emit('webviewCode', msg);  
                }  
            })

webview中。

// 待触发 `UniAppJSBridgeReady` 事件后,即可调用 uni 的 API。  
document.addEventListener('UniAppJSBridgeReady', function() {  
uni.webView.getEnv(function(res) {  
console.log('当前环境:' + JSON.stringify(res));  
if (res.h5) {  
//$('body').css('background-color', 'transparent');  
//  h5  
h5Ready();  
} else if (res.plus) {  
// 通知到APP  
//  此处理是关键, 传参内容入在 对象的data属性中。  
uni.postMessage({data: {status: 1}});  
//if(window.plus){  
//     plusReady();  
//}else{  
//    document.addEventListener('plusready', plusReady, false);  
// }  
}  
});  
});

sdk原码

0 关注 分享

要回复文章请先登录注册