Nativescript 应用程序 - 在 Webview 中加载本地 HTML/JS/CSS
Nativescript App - load local HTML/JS/CSS in Webview
如果我想在 Webview 中显示本地 html 文件,我该怎么做?
尝试过的解决方案:
- 各自的绝对路径 html 我想在 webview 中显示,如下所示:
Absolute path/ encodeURI
this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/monitordaten/webview/assets/graph.html`);
<Webview #myWebView [src]="htmlPath" ></Webview>
- 像这样编辑webpack.config.js:
这里提到了这个解决方案:
new CopyWebpackPlugin([
{ from: { glob: "monitrodaten/webview/assets/**"} }, <= Added this row
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
...
两种解决方案都会导致以下错误:
文件结构:
您的路径缺少“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/**"} }
如果我想在 Webview 中显示本地 html 文件,我该怎么做?
尝试过的解决方案:
- 各自的绝对路径 html 我想在 webview 中显示,如下所示:
Absolute path/ encodeURI
this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/monitordaten/webview/assets/graph.html`);
<Webview #myWebView [src]="htmlPath" ></Webview>
- 像这样编辑webpack.config.js:
这里提到了这个解决方案:
new CopyWebpackPlugin([
{ from: { glob: "monitrodaten/webview/assets/**"} }, <= Added this row
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
...
两种解决方案都会导致以下错误:
您的路径缺少“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/**"} }