【发布时间】:2020-04-10 07:18:24
【问题描述】:
我有以下对象(在里面操作了一些点之后) 我称之为 props.stuff , 给定:数据从父组件传递到子组件为
//Parent
componentDidMount() {
this.getData();
}
async getData() {
const res = await axios.get(
"{link here}"
);
const { data } = await res;
this.setState({ stuff: data});
}
<Child props={this.state.stuff} />
所以,当我做 console.log(props.stuff):
props.stuff= {
"date":"November 14",
"status":"PENDING",
"id":"146859",
"invoice_number":"123685479624",
"amount":"950.00",
"currency":"$"
}
但尝试访问 props.stuff.date(或类似 props.stuff.{element} 的东西)给了我undefined。 我做错了什么?
注意:我通过执行 console.log(JSON.stringify(props.stuff)) 得到了下面的字符串,所以这正是它。
【问题讨论】:
-
请添加minimal reproducible example。还要注意there is no such thing as a JSON object:要么是 JSON 字符串,要么是对象。
标签: javascript json reactjs string