【问题标题】:Headless webview无头网络视图
【发布时间】:2019-05-06 04:26:24
【问题描述】:

有没有办法在 Nativescript (Vue) 中创建一个无头 WebView 实例以用于 nativescript-webview-interface(需要 Nativescript 视图)?如何实例化 Vue 组件,以便它在后台创建原生 webview(类似于 web 上的document.createElement)?

【问题讨论】:

    标签: ios nativescript wkwebview nativescript-vue


    【解决方案1】:

    尝试创建元素的核心方式

    import { WebView } from "tns-core-modules/ui/web-view";
    
    ...
    methods: {
       createWebView: function() {
          const webView = new WebView();
          // Remember to pass in context in case of android
          wv._setupAsRootView({});
          wv.onLoaded();
          ...
       }
    }
    ...
    

    【讨论】:

    • 这没有正确初始化 web 视图(底层 WKWebView 没有创建)。因此尝试在 nativescript-webview-interface 中使用它会导致 undefined is not an object (evaluating 'this.webView.ios.constructor') 崩溃,因为 ios 属性尚不存在。 Playground
    • 我已经更新了你的playground
    • 我还必须添加 wv.onLoaded() 以使其正确初始化。 Playground 演示工作 WVI。
    • 是的,没错。感谢您的关注和分享,我已经更新了 sn-p。
    猜你喜欢
    • 1970-01-01
    • 2015-06-16
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    相关资源
    最近更新 更多