我想从 Application Support 文件夹中动态地要求图像。我使用 react-app-rewired 包在 src 文件夹之外要求,但是当我在图像 src 中使用窗口变量时,我收到错误:错误:找不到module。我得到这样的路径并得到一个带有字符串的错误代码,当我直接在图像标签的 src 部分使用它时,该字符串有效。
window.path = window.electron.remote.app.getPath("appData")
图像(不起作用):
<img className="topSvg" src={require(""+window.path+'/current/'+this.props.project+'/src/content/img/changeable/'+data.top.img)} alt="top_svg"/>
Error: Cannot find module '/Users/tobi/Library/Application Support/template-editor/current/Tobi/src/content/img/changeable/top_svg.svg'
图像(作品):
<img className="topSvg" src={require('/Users/tobi/Library/Application Support/template-editor/current/Tobi/src/content/img/changeable/top_svg.svg')} alt="top_svg"/>
我还尝试将 window.path 替换为字符串“/Users/tobi/Library/Application Support/template-editor”,这也可以正常工作