首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法读取null属性(读取“type”)

无法读取null属性(读取“type”)
EN

Stack Overflow用户
提问于 2022-06-05 13:16:28
回答 2查看 320关注 0票数 0

我试着实施反应灵敏的旋转木马。它适用于静态链接,但当我试图从db获取数据时,会出现错误。我试着测试我是否获得了console.log(imagemap)的链接,并且它工作得很好。I getting:'https://www.top-magazin-frankfurt.de/wp-content/up…1/12/Das-%E2%80%9EFranziska-im-Henninger-Turm.jpg','https://www.zeitlos-erding.de/wp-content/uploads/2…6/04/Zeitlos-Erding-Website-Restaurant-Bild-6.jpg‘

但是,当我试图在旋转木马中执行此操作时,我会得到以下错误:无法读取null属性(读取“type”)

代码语言:javascript
复制
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import 'react-responsive-carousel/lib/styles/carousel.min.css'; // requires a loader
import { Carousel } from 'react-responsive-carousel';

const Ambience = () => {
  const [images, setImages] = useState([]);
  useEffect(() => {
    const getImages = async () => {
      const res = await axios.get('/api/galery');
      setImages(res.data);
    };

    getImages();
  }, []);
  const imagemap = images.map((url) => {
    return url.name;
  });
  console.log(imagemap);
  return (
    <div className='min-h-screen'>
      <Carousel showArrows={true} showThumbs={true}>
        {images.map((url, index) => {
          <div key={index}>
            <img src={url.name} />
          </div>;
        })}
      </Carousel>
    </div>
  );
};

export default Ambience;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-06-05 13:26:49

您忘了在return中写Carousel

代码语言:javascript
复制
<Carousel showArrows={true} showThumbs={true}>
    {images.map((url, index) => {
      return (
         <div key={index}>
            <img src={url.name} />
         </div>);
     })}
</Carousel>
票数 1
EN

Stack Overflow用户

发布于 2022-06-05 13:32:48

代码语言:javascript
复制
  import React, { useState, useEffect } from 'react';
  import axios from 'axios';
  import 'react-responsive-carousel/lib/styles/carousel.min.css'; // requires a loader
  import { Carousel } from 'react-responsive-carousel';

  interface IMAGES {
   name: string;
  }

  const Ambience = () => {
  const [images, setImages] = useState<IMAGES[]>([]);
  useEffect(() => {
  const getImages = async () => {
  const res = await axios.get('/api/galery');
   setImages(res.data);
  };
   getImages();
 }, []);

  return (
  <div className='min-h-screen'>
  <Carousel showArrows={true} showThumbs={true}>
    {images.map((url, index) => (
      <div key={index}>
        <img src={url.name} />
      </div>;
    ))}
  </Carousel>
</div>
); 
};
export default Ambience;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72507643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档