8***@qq.com
8***@qq.com
  • 发布:2025-04-25 00:24
  • 更新:2025-04-25 00:24
  • 阅读:48

uniapp在安卓app平台使用evalJS执行html中的js函数提示未定义

分类:uni-app

vue端:
<template>
<view>
<web-view ref="webview" src="/hybrid/html/test.html"></web-view>
</view>
</template>

<script>
export default {
data() {
return {

        }  
    },  
    onLoad: function(option) {  
        this.openWebViewPopup()  
    },  
    methods: {  
        openWebViewPopup() {  

            console.log("webview----1>")  
            setTimeout(() => {  

                let data = {"a":1}  
                console.log("webview---2>")  
                const webview = this.$scope.$getAppWebview();  
                webview.evalJS(`receiveData('${JSON.stringify(data)}')`);  

            }, 3500);  

          },  

    }  
}  

</script>

h5端:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>

</head>  
<body>  
    <h1>测试html</h1>  
</body>  

</html>
<script>
window.receiveData = (data) => {
console.log('Received from UniApp:', data);
};
</script>

2025-04-25 00:24 负责人:无 分享
已邀请:

要回复问题请先登录注册