reactjs - 如何在 React js 项目中为文本添加 js 文件?
问题描述
我在项目中有很多文本,所以我只为文本制作了一个 js 文件,并将这个文件添加到 index.html,当使用这个文件时有错误,但是当检查代码时我可以看到文本,
faBundleForms.js
const forms = {
changeProfitDate: {
note_1: 'user ',
note_2: 'add '
}
};
add to index.html
`<script src="../static/faBundleForms.js" type="text/javascript">`</script>
use to project
<p>{forms.changeProfitDate.note_1}</p>
我有这个错误
'forms' is not defined
解决方案
如果你真的想使用全局变量(这是个坏主意),你需要window.
在它们之前使用,像这样:<p>{window.forms.changeProfitDate.note_1}</p>
推荐阅读
- javascript - Javascript JSON.stringify 更改包含反斜杠的字符串
- python - Pandas pd 没有填充 .append
- python - 在 Cython 中使用 ZMQ
- python - 在 Excel 列中搜索字符串
- java - 如何获取所有消费者队列rabbitMq的列表?
- javascript - SuiteScript 错误 - Catch(e) - e 未定义
- flutter - 如何在颤动中创建数字选择器作为警报对话框?
- android - Android Studio 编译 Telegram 源码
- javascript - 进度条结束后如何重置
- excel - 从 Python 执行 Excel 宏而不重新打开文件