【浙里办】UniApp如何引入ZWJSBridge

388 阅读1分钟

第一步

  1. 在根目录下,可能项目创建就存在,没有就创建 index.html
  2. 将代码复制到 index.html 中,js版本自行修改
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title><%= htmlWebpackPlugin.options.title %></title>
        <script>
            document.addEventListener("DOMContentLoaded", function() {
                document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + "px";
            });
            var coverSupport = "CSS" in window && typeof CSS.supports === "function" && (CSS.supports("top: env(a)") ||
                CSS.supports("top: constant(a)"));
            document.write(
                '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
                (coverSupport ? ", viewport-fit=cover" : "") +
                '" />'
            );
        </script>
        <link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
    </head>

    <body>
        <script type="text/javascript" src="//assets.zjzwfw.gov.cn/assets/ZWJSBridge/1.0.1/zwjsbridge.js"></script>
        <div id="app"></div>
    </body>
</html>

第二步

  1. 在manifest.json中,可能项目创建就存在,不存在就添加,将 index.html 引入
"h5": {
    "template": "index.html"
}

第三步

  1. 重启软件,重启项目,运行到政务中台
  2. 再合适的地方调用 ZWJSBridge
ZWJSBridge.onReady(() => {
    ZWJSBridge.getUiStyle().then(res => {
        console.log(res)
    })
})