reactjs - React 应用程序在 localhost 上运行,但在 github 或 heroku 上部署时出错。部署时没有错误
问题描述
我创建了一个反应应用程序来显示不同国家的电晕感染情况。这在我的本地主机上工作,但是当我在 github 或 heroku 上部署它时,会产生错误。以下错误在块引用中给出。当我检查文件country.js时查看错误,没有n[0]。请帮助下面是托管应用程序和应用程序 github 存储库的链接。
TypeError: "n[0] is undefined" E country.js:13 E country.js:11 React 7 stable_runWithPriority scheduler.production.min.js:19 React 6 a App.js:22 u runtime.js:45 _invoke runtime .js:274 t runtime.js:97 r asyncToGenerator.js:3 aasyncToGenerator.js:25 react-dom.production.min.js:209:194 React 5不稳定_runWithPriority scheduler.production.min.js:19 React 4不稳定_runWithPriority scheduler.production.min.js:19 React 6 a App.js:22 u runtime.js:45 _invoke runtime.js:274 t runtime.js:97 r asyncToGenerator.js:3 a asyncToGenerator.js:25 TypeError: n [0] 未定义 country.js:13:30
这 是指向 Heroku 上托管应用程序的链接 , 这是指向 Github上托管应用程序的链接
解决方案
正如Dishant Desai 所说,它给出了一个 TypeError。为了修复它,您可以将代码更改country.js
为
const countryflag = Object.keys(data).map((name) => {
return data[name][0];
})
到
const countryflag = data[0];
并以这种方式直接使用它:
${countryflag[country[0]]}
推荐阅读
- html - 如何显示我的网站图标,它的路径没问题
- wpf - SpirePDF :- 高分辨率图像被像素化或剪切?
- c++ - 无法通过 UDP 发送数据
- javascript - 当我使用 angularjs 在元素中使用 ng-click 时,$watch 不会触发
- neural-network - 如何使用 PyTorch 计算神经网络中输入的输出梯度?
- php - 带有 PHP 和 MYSQL 的响应式垂直多级菜单
- ios - 将滑块值设置为文本视图中的当前读取位置
- javascript - 如何使用 { 对列表进行分组
- php - SparkPost 电子邮件不起作用
- c++ - 功能延迟时计时器停止