p***@jsask.cn
p***@jsask.cn
  • 发布:2026-04-29 18:12
  • 更新:2026-04-29 18:12
  • 阅读:20

APP云打包无法触发uni.postMessage唤起APP

分类:uni-app

HBuilder X 5.07

双端,uniapp开发app,java开发接口,业务需要调用java端html,使用了uni.postMessage来在html中唤起app,在使用自定义基座测试时唤起正常,使用默认安卓基座无法唤起app,云打包后同样无法唤起app

大佬指导一下这是为什么,是因为HBuilder X太新了?

<!DOCTYPE html>  
<html lang="en" xmlns:th="http://www.thymeleaf.org">  
<head>  
    <meta charset="UTF-8">  
    <title>京东订单收银台</title>  
    <!-- uni-app SDK -->  
    <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>  
</head>  
<style>  
</style>  
<body>  
</body>  
<script>  
    document.addEventListener('UniAppJSBridgeReady', function () {  
        const urlParams = new URLSearchParams(window.location.search);  
        const orderId = urlParams.get('orderId');  
        console.log("唤起APP", orderId)  
        uni.postMessage({  
            data: orderId  
        })  
    });  
</script>  
</html>
<template>  
    <view>  
        <view>  
            <web-view :webview-styles="webviewStyles" :src="urltoJd" @message="onMessage"></web-view>  
        </view>  
    </view>  
</template>  
<script>  
    export default {  
        data() {  
            return {  
                urltoJd: "",  
                webviewStyles: {  
                    progress: {  
                        color: '#FF3333'  
                    }  
                },  
                urlArr: []  
            }  
        },  
        watch: {  
            urltoJd(newVal) {  
                this.urlArr.push(newVal)  
            }  
        },  
        onLoad() {  
            //设置userAgent代理  
            plus.navigator.setUserAgent("Mozilla/5.0 (Linux; Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");  

            let _this = this;  
            uni.request({  
                header: {  
                    Authorization: 'Bearer ' + this.$Common.getToken()  
                },  
                url: this.$Common.serverUrl + "/jd/flLogin";,  
                method: 'GET',  
                dataType: 'json',  
                success: res => {  
                    let item = res.data;  
                    if (item.code == 200) {  
                        _this.urltoJd = res.data.data;  
                    } else {  
                        _this.$Common.requestFail(item);  
                    }  
                }  
            });  
        },  
        methods: {  
            onMessage(e) {  
                if (e && e.detail.data) {  
                    let data = e.detail.data  
                    this.$scope.$getAppWebview().children()[0].back();  
                    uni.navigateTo({  
                        url: '/pages/index/cash_register?orderId=' + e.detail.data[0]  
                    })  
                }  
            }  
        }  
    }  
</script>  

<style>  
</style>
2026-04-29 18:12 负责人:无 分享
已邀请:

要回复问题请先登录注册