开发者问题收集

Nativescript App-在 Webview 中加载本地 HTML/JS/CSS

2020-09-15
246

如果我想在 Webview 中显示本地 html 文件,我该怎么做?

尝试过的解决方案:

this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/monitordaten/webview/assets/graph.html`); 
<Webview #myWebView [src]="htmlPath" ></Webview>
new CopyWebpackPlugin([
               { from: { glob: "monitrodaten/webview/assets/**"} },          <= Added this row
               { from: { glob: "fonts/**" } },
               { from: { glob: "**/*.jpg" } },
               ...

两种解决方案都会导致以下错误: 在此处输入图片说明 文件结构:
在此处输入图片说明

1个回答

您的路径缺少“app”

this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/app/monitordaten/webview/assets/graph.html`); 

this.htmlPath = encodeURI(`~/app/monitordaten/webview/assets/graph.html`);

webpack 配置

{ from: { glob: "app/monitrodaten/webview/assets/**"} }
Yong
2020-09-15