import React, { Component } from 'react';
class newsList extends React.Component {
render(){
return(
<div>
{JSON.stringify(this.props.arr)}
</div>
)
}
}
export default newsList;
在上面的代碼中,arr
是來自另一個組件的對象。我可以使用JSON.stringify(this.props.arr.result)
來顯示數據。但只要我將其更改爲JSON.stringify(this.props.arr.result.id)
,就會收到錯誤消息0123'。我無法理解我在這裏做錯了什麼?如何訪問反應組件中的道具?
你能提供一個'props'的樣子嗎? –
,因爲它對你的'arr'對象有問題,所以最好顯示數據。 – wakwak
更有可能的是,你的'this.props.arr'在你的代碼中的某個時候是'undefined'。 – Andrew