首页 > 解决方案 > Headless webview

问题描述

Is there a way to create a headless WebView instance in Nativescript (Vue) for use with nativescript-webview-interface (which expects a Nativescript view)? How can I instantiate the Vue component so it creates the native webview in the background (similar to document.createElement on web)?

标签: iosnativescriptwkwebviewnativescript-vue

解决方案


尝试创建元素的核心方式

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();
      ...
   }
}
...

推荐阅读