酷酷_
酷酷_
  • 发布:2023-05-29 09:17
  • 更新:2023-05-29 13:01
  • 阅读:316

使用web-view组件加载本地HTML文件,HTML文件里无法使用uni的api

分类:uni-app

使用web-view组件加载本地HTML文件,HTML文件里无法使用uni的api 例如:uni.navigateTo

2023-05-29 09:17 负责人:无 分享
已邀请:
Diligent_UI

Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

肯定不能使用啊

  • 酷酷_ (作者)

    无解了吗?

    2023-05-29 09:35

Diligent_UI

Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

需要引入uni 的 SDK

  • 酷酷_ (作者)

    大神啊!怎么引入呢 有教程吗?

    2023-05-29 09:51

6***@qq.com

6***@qq.com

官方实例都没看么?

  • 酷酷_ (作者)

    有网址吗?大神

    2023-05-29 09:56

  • 6***@qq.com

    回复 h***@qq.com: https://uniapp.dcloud.net.cn/component/web-view.html#web-view

    2023-05-29 09:59

  • 酷酷_ (作者)

    回复 6***@qq.com:我试了 Hbuilder预览可以调用了,但是H5平台打包出来以后无法调用,这是怎么回事啊???

    2023-05-29 10:24

6***@qq.com
  • 酷酷_ (作者)

    这个加了 还是不行呢 是不是还有哪里配置的不对 只有打包发行后不能调用啊

    2023-05-29 11:29

酷酷_

酷酷_ (作者)

在Hbuilder预览是正常的 但是打包发行后 访问 就报错了

6***@qq.com

6***@qq.com

把uni.webview保存到项目内, 改源码, 全局替换 uni

  • 酷酷_ (作者)

    能把这个改过的文件发给我吗? QQ:648195056

    2023-05-29 12:11

  • 酷酷_ (作者)

    把uni 改成 uniWeb???

    2023-05-29 12:12

  • 酷酷_ (作者)

    我就是把SDK放在本地目录了 1.5.4版本的

    2023-05-29 12:16

6***@qq.com

6***@qq.com

! function(e, n) {  
  "object" == typeof exports && "undefined" != typeof module ? module.exports = n() : "function" == typeof define &&  
    define.amd ? define(n) : (e = e || self).uniWeb = n()  
}(this, (function() {  
  "use strict";  
  try {  
    var e = {};  
    Object.defineProperty(e, "passive", {  
      get: function() {  
        !0  
      }  
    }), window.addEventListener("test-passive", null, e)  
  } catch (e) {}  
  var n = Object.prototype.hasOwnProperty;  

  function i(e, i) {  
    return n.call(e, i)  
  }  
  var t = [];  

  function o() {  
    return window.__dcloud_weex_postMessage || window.__dcloud_weex_  
  }  
  var r = function(e, n) {  
      var i = {  
        options: {  
          timestamp: +new Date  
        },  
        name: e,  
        arg: n  
      };  
      if (o()) {  
        if ("postMessage" === e) {  
          var r = {  
            data: [n]  
          };  
          return window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessage(r) : window.__dcloud_weex_  
            .postMessage(JSON.stringify(r))  
        }  
        var a = {  
          type: "WEB_INVOKE_APPSERVICE",  
          args: {  
            data: i,  
            webviewIds: t  
          }  
        };  
        window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessageToService(a) : window.__dcloud_weex_  
          .postMessageToService(JSON.stringify(a))  
      }  
      if (!window.plus) return window.parent.postMessage({  
        type: "WEB_INVOKE_APPSERVICE",  
        data: i,  
        pageId: ""  
      }, "*");  
      if (0 === t.length) {  
        var d = plus.webview.currentWebview();  
        if (!d) throw new Error("plus.webview.currentWebview() is undefined");  
        var s = d.parent(),  
          w = "";  
        w = s ? s.id : d.id, t.push(w)  
      }  
      if (plus.webview.getWebviewById("__uniapp__service")) plus.webview.postMessageToUniNView({  
        type: "WEB_INVOKE_APPSERVICE",  
        args: {  
          data: i,  
          webviewIds: t  
        }  
      }, "__uniapp__service");  
      else {  
        var u = JSON.stringify(i);  
        plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat("WEB_INVOKE_APPSERVICE",  
          '",').concat(u, ",").concat(JSON.stringify(t), ");"))  
      }  
    },  
    a = {  
      navigateTo: function() {  
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},  
          n = e.url;  
        r("navigateTo", {  
          url: encodeURI(n)  
        })  
      },  
      navigateBack: function() {  
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},  
          n = e.delta;  
        r("navigateBack", {  
          delta: parseInt(n) || 1  
        })  
      },  
      switchTab: function() {  
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},  
          n = e.url;  
        r("switchTab", {  
          url: encodeURI(n)  
        })  
      },  
      reLaunch: function() {  
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},  
          n = e.url;  
        r("reLaunch", {  
          url: encodeURI(n)  
        })  
      },  
      redirectTo: function() {  
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},  
          n = e.url;  
        r("redirectTo", {  
          url: encodeURI(n)  
        })  
      },  
      getEnv: function(e) {  
        o() ? e({  
          nvue: !0  
        }) : window.plus ? e({  
          plus: !0  
        }) : e({  
          h5: !0  
        })  
      },  
      postMessage: function() {  
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};  
        r("postMessage", e.data || {})  
      }  
    },  
    d = /uni-app/i.test(navigator.userAgent),  
    s = /Html5Plus/i.test(navigator.userAgent),  
    w = /complete|loaded|interactive/;  
  var u = window.my && navigator.userAgent.indexOf("AlipayClient") > -1;  
  var g = window.swan && window.swan.webView && /swan/i.test(navigator.userAgent);  
  var c = window.qq && window.qq.miniProgram && /QQ/i.test(navigator.userAgent) && /miniProgram/i.test(navigator  
    .userAgent);  
  var v = window.tt && window.tt.miniProgram && /toutiaomicroapp/i.test(navigator.userAgent);  
  var m = window.wx && window.wx.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(  
    navigator.userAgent);  
  var p = window.qa && /quickapp/i.test(navigator.userAgent);  
  var f = window.ks && window.ks.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(  
    navigator.userAgent);  
  var l = window.tt && window.tt.miniProgram && /Lark|Feishu/i.test(navigator.userAgent);  
  var _ = window.jd && window.jd.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(  
    navigator.userAgent);  
  for (var E, b = function() {  
      window.UniAppJSBridge = !0, document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady", {  
        bubbles: !0,  
        cancelable: !0  
      }))  
    }, h = [function(e) {  
      if (d || s) return window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? document.addEventListener(  
          "DOMContentLoaded", e) : window.plus && w.test(document.readyState) ? setTimeout(e, 0) : document  
        .addEventListener("plusready", e), a  
    }, function(e) {  
      if (m) return window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document  
        .addEventListener("WeixinJSBridgeReady", e), window.wx.miniProgram  
    }, function(e) {  
      if (c) return window.QQJSBridge && window.QQJSBridge.invoke ? setTimeout(e, 0) : document  
        .addEventListener("QQJSBridgeReady", e), window.qq.miniProgram  
    }, function(e) {  
      if (u) {  
        document.addEventListener("DOMContentLoaded", e);  
        var n = window.my;  
        return {  
          navigateTo: n.navigateTo,  
          navigateBack: n.navigateBack,  
          switchTab: n.switchTab,  
          reLaunch: n.reLaunch,  
          redirectTo: n.redirectTo,  
          postMessage: n.postMessage,  
          getEnv: n.getEnv  
        }  
      }  
    }, function(e) {  
      if (g) return document.addEventListener("DOMContentLoaded", e), window.swan.webView  
    }, function(e) {  
      if (v) return document.addEventListener("DOMContentLoaded", e), window.tt.miniProgram  
    }, function(e) {  
      if (p) {  
        window.QaJSBridge && window.QaJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener(  
          "QaJSBridgeReady", e);  
        var n = window.qa;  
        return {  
          navigateTo: n.navigateTo,  
          navigateBack: n.navigateBack,  
          switchTab: n.switchTab,  
          reLaunch: n.reLaunch,  
          redirectTo: n.redirectTo,  
          postMessage: n.postMessage,  
          getEnv: n.getEnv  
        }  
      }  
    }, function(e) {  
      if (f) return window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document  
        .addEventListener("WeixinJSBridgeReady", e), window.ks.miniProgram  
    }, function(e) {  
      if (l) return document.addEventListener("DOMContentLoaded", e), window.tt.miniProgram  
    }, function(e) {  
      if (_) return window.JDJSBridgeReady && window.JDJSBridgeReady.invoke ? setTimeout(e, 0) : document  
        .addEventListener("JDJSBridgeReady", e), window.jd.miniProgram  
    }, function(e) {  
      return document.addEventListener("DOMContentLoaded", e), a  
    }], y = 0; y < h.length && !(E = h[y](b)); y++);  
  E || (E = {});  
  var B = "undefined" != typeof uniWeb ? uniWeb : {};  
  if (!B.navigateTo)  
    for (var S in E) i(E, S) && (B[S] = E[S]);  
  return B.webView = E, B  
}));  
  • 酷酷_ (作者)

    试了uniWeb 还是报一样的错

    2023-05-29 14:25

要回复问题请先登录注册