无法读取未定义的 React Js 的属性“协议”

拉胡尔·拉吉

如何显示 JSON 文件中的 author.name 数据,因为我在尝试运行时遇到错误我是 react js 新手,因此请指导我如何解决此错误,我还添加了错误页面图像,以便您可以看到

class Details extends Component {
    constructor(props){
        super(props);

        this.state = {
            question: [],
          };
    }

  componentDidMount() {
    axios.get(`http://trivago-magazine-work-sample-server.s3-website.eu-central-1.amazonaws.com/dornoch-castle-scotland-whisky.json`)
      .then(res => {
        const question = res.data;
        console.log(res);
        this.setState({ question });
      })

  }


    render() {
        const {question} = this.state;

        if (question === null) return <p>Loading ...</p>;
        return (
            <div>

            <Container>
                <Row >

                    <h4>{question.author.name}</h4> //This Line when i try to show author.name it showing error 

                </Row>
            </Container>



            </div>
        )
    }
}

export default Details

这是错误页面的图像

青蛙

初始状态应为{ question: null },以便if (question === null)生效并呈现“正在加载...”消息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React.js:无法读取未定义的属性“ myProp”

react js无法读取未定义的属性“ id”

React.js-无法读取未定义的属性

无法读取未定义的属性“ bind”。React.js

无法读取未定义 React JS 的“handleClick”属性

React JS 无法读取未定义的属性“地图”

无法读取React JS中未定义的属性'map'

无法读取未定义的属性“ id”-REACT JS

无法读取未定义 React js 的属性“show”

无法读取未定义的React JS的属性'map'

React.js“无法读取未定义的属性‘地图’”

React js 错误:无法读取未定义的属性“0”

React js TypeError:无法读取未定义的属性“params”

错误:无法读取未定义的 REACT JS 的属性“地图”

无法读取未定义的属性“协议”:axios react

类型错误:无法读取 react.js 中未定义的属性(读取“addEventListener”)

无法使用 Firebase v9 Modular React JS 读取未定义的属性(读取“indexOf”)

无法在 React JS 中读取未定义的属性(读取“包含”)

无法读取未定义的属性(读取“方向”)React JS 材料表

无法解决错误无法读取react js中未定义的属性“ map”

无法在Mac上运行React JS。'TypeError:无法读取未定义的属性'render'

React JS:从 React.createClass 更新时无法读取未定义的属性“setState”

React无法读取未定义的属性

类型错误:无法读取未定义的属性“中心”(Three.js + React.js)

TypeError:无法读取未定义React.js的属性“ map”

React.js错误:TypeError:无法读取未定义的属性'map'

类型错误:无法读取 Netlify CMS/React.js 上未定义的属性“映射”

React.JS TypeError:无法读取未定义的属性“编号”-(在 setState 中)

未捕获的类型错误:无法读取未定义的 React js 的属性“推送”