json - 从API获取数据时如何解决React js中的未定义错误?
问题描述
收到类似 TypeError 着陆的错误。插槽未定义
<div className="notification" />
</header>
<main
style={
ready
? {}
: {
height: "100vh",
overflow: "hidden"
}
}>
<LandingLoader className={ready ? "fade-out" : ""} />
<ul
className="slots"
style={{
visibility: ready ? "visible" : "hidden"
}}>
{landing &&
landing.Slots.map((slot,index) => {
if (slot && !slot.removed) {
let fullWidth = "100%";
let maxWidth = 576;
let style = {};
style["width"] = fullWidth;
style["maxWidth"] = fullWidth;
style["height"] = slot.HeightPixel + "px";
return (
<li key={index} className="slots" style={style}>
<Slot slotItem={slot} slotIndex={index} />
</li>
);
}
})}
</ul>
</main>
</div>
解决方案
您可以为插槽添加另一个检查,例如
landing && landing.Slots && landing.Slots.map
还请检查,是Slots
还是slots
。可能是拼写错误
推荐阅读
- aws-lambda - 在 Lambda 代理集成中通过 API Gateway 传递 multipart/form-data
- javascript - 从对象数组 JavaScript 中提取所有数组?
- sql - 如何获取特定交易的起始值和结束值
- php - Laravel Auth 登录页面刚刚刷新
- python - 如何获得 SGDClassifier (LinearSVM) 的概率
- php - 使用 Laravel 和 Dropzone 图片上传数据中插入的 id
- c# - 使用字符串 C# 引用 XAML
- java - XMLDecoder >> java.lang.IllegalArgumentException:不支持的元素
- java - 如何使用 Jackson 序列化为 java.util.List 和 java.util.Map
- node.js - 无法使用 AWS SES 发送电子邮件:我没有正确配置它吗?