Nativescript App-在 Webview 中加载本地 HTML/JS/CSS
2020-09-15
246
如果我想在 Webview 中显示本地 html 文件,我该怎么做?
尝试过的解决方案:
-
我想在 Webview 中显示的相应 html 的绝对路径,如下所示:
绝对路径/encodeURI
this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/monitordaten/webview/assets/graph.html`);
<Webview #myWebView [src]="htmlPath" ></Webview>
-
像这样编辑 webpack.config.js:
此解决方案在此处提及: 编辑webpack.config.js
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