gpt4 book ai didi

javascript - Electron 根据命令重新加载特定的 JS 文件

转载 作者:太空宇宙 更新时间:2023-11-04 01:55:25 24 4
gpt4 key购买 nike

我最近一直在开发一个 Electron 应用程序,该应用程序需要将数据存储在 javascript 文件中,该文件在用户登录并显示时解密,并在用户注销时加密。但是,登录后,用户可以选择将数据添加到 javascript 文件。但不幸的是,当此过程完成时,尽管在初始显示中使用与重新加载中完全相同的代码,但新数据并未显示。我确信这是由于需要重新加载 javascript 文件(Electron 未注册文件更改)。我尝试过 Electron-reload 模块,但它似乎只允许实时重新加载。我需要一个模块或解决方案来允许我做这样的事情。

var reload = require('some-reload-module');
reload.reload('../path/to/file.js');
...

任何解决方案都将受到欢迎,因为到目前为止我还没有运气。预先感谢您!

最佳答案

发生这种情况是因为 require caches its resultsrequire.cache 中。要解决这个问题,您可以只需 delete the entry in the cache .

// Initially require the file; the result is cached.
require('../path/to/file.js');

// Delete the cached version of the module.
delete require.cache[require.resolve('../path/to/file.js')];

// Re-require the file; the file is re-executed and the new result is cached.
require('../path/to/file.js');

关于javascript - Electron 根据命令重新加载特定的 JS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48178322/

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