gpt4 book ai didi

node.js - 如何使用webview加载本地html文件

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:12 28 4
gpt4 key购买 nike

我正在构建一个 Electron 应用程序,我在开发中使用此代码加载 html 文件:

<webview id="foo" src="/src/documents/example.html" style="display:inline-flex; width:100%; height:550px"></webview>

这在开发中效果很好,但是一旦应用程序打包,它就会显示一个空白页面。我进行了研究,似乎使用 __dirname 可能会解决这个问题。

我对 Electron 还很陌生,不知道如何使用__dirname到达此路径(src="/src/documents/)

任何帮助将不胜感激。

最佳答案

我想我会分享我找到的解决方案。基本上,您需要为要加载的页面创建一条路由,如下所示:

{
path:'/example',
name:'example',
component: require('@/components/example').default
},

如果您使用 Electron-Vue,请确保页面扩展名是“.vue”并包含如下页面内容:

<template>
<html>
**Put the page content in here**
</html>
</template>

就我而言,我想通过单击按钮进入页面,所以我使用了这样的 Vue-router:

<button type="button" class="btn btn-light"><a id="home"><router-link :to="{ name: 'example' }"> Button text </router-link></a>
</button>

瞧瞧!

关于node.js - 如何使用webview加载本地html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53150313/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com