如何将本地 html 文件加载到 NativeScript webview
How to load a local html file into a NativeScript webview
我修改了 webpack.config.js 以添加名为 index.html 的本地文件,代码如下:
new CopyWebpackPlugin([
{ from: { glob: "index.html" } },
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
{ from: { glob: "**/*.png" } },
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
这就是我在主 page.xml 文件中配置我的 webview 的方式,代码如下:
<WebView row="1" loaded="onWebViewLoaded" id="myWebView" src="index.html"/>
在 NativeScript 中,默认情况下波浪号 (~
) 标记应用程序根文件夹(注意应用程序而不是项目!)。因此,如果您的文件位于 <project-name>/app/index.html
中,请尝试使用 ~/index.html
.
设置路径
我修改了 webpack.config.js 以添加名为 index.html 的本地文件,代码如下:
new CopyWebpackPlugin([
{ from: { glob: "index.html" } },
{ from: { glob: "fonts/**" } },
{ from: { glob: "**/*.jpg" } },
{ from: { glob: "**/*.png" } },
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
这就是我在主 page.xml 文件中配置我的 webview 的方式,代码如下:
<WebView row="1" loaded="onWebViewLoaded" id="myWebView" src="index.html"/>
在 NativeScript 中,默认情况下波浪号 (~
) 标记应用程序根文件夹(注意应用程序而不是项目!)。因此,如果您的文件位于 <project-name>/app/index.html
中,请尝试使用 ~/index.html
.