从API提取数据时,如何解决React js中的未定义错误?

时间:2019-01-24 05:16:19

标签: json reactjs api

  

我遇到类似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>

1 个答案:

答案 0 :(得分:0)

您可以为广告位添加另一个检查,例如

landing && landing.Slots && landing.Slots.map

也请检查是Slots还是slots。可能是拼写错误