uniapp生成h5与小程序webview交互

在static中新建index.html并注入微信jssdk,web配置中设置index路径

调用:

jWeixin.miniProgram.postMessage({
                    data: {
                        type: 'share',
                        url: "11111"
                    }
                })

注意是jWeixin不是wx!!!注意是jWeixin不是wx!!!注意是jWeixin不是wx!!!

index.html模板

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <link rel="icon" href="<%= BASE_URL %>static/logo.png">
        <link rel="stylesheet" href="<%= BASE_URL %>static/index.css" />
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
     <script type="text/javascript" src="<%= BASE_URL %>static/jweixin-1.3.2.js"></script>
        
        
    </head>
    <body>
        <noscript>
            <strong>Please enable JavaScript to continue.</strong>
        </noscript>
        <div id="app"></div>
    </body>
    
    

</html>
<script>

            
</script>

小程序调用:

<web-view src="111.html" style="" @bindmessage="bindmessage"></web-view>

methods中

bindmessage(e){
                console.log('网页消息')
                console.log(e)
            },

posted on 2023-08-15 09:36  Just丶随心  阅读(53)  评论(0编辑  收藏  举报

导航