H5 如何和uniapp微信小程序互通

index.html 中引入微信所需要的js

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>大连</title>
    <script type="text/javascript" src="/wx/wxSDK/jweixin-1.4.0.js"></script>
    <script type="text/javascript" src="/wx/uniwebview/uni.webview.1.5.5.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

使用方法

<img @click="seeCoupon" class="button" src="@/assets/png/year/button.png">


const seeCoupon = () => {
  uni.webView.navigateBack()
  uni.webView.postMessage({
    data: {
      action: "page",
      params: 'page_mall/pages/home'
    }
  });
}
posted @ 2025-07-15 19:24  DL·Coder  阅读(10)  评论(0)    收藏  举报