我需要从对象 this.props.payload
获取 3 个变量 cx
、cx
和 weatherIcon
目前我正在使用这段代码
const { cx, cy } = this.props
const {weatherIcon} = this.props.payload
它可以工作,但我想知道是否可以写在一行中。
最佳答案
试试这个。
const { cx, cy, payload: { weatherIcon } } = this.props;
const props = { cx: 1, cy: 2, payload: { weatherIcon: 3 }};
const { cx, cy, payload: { weatherIcon } } = props;
console.log(cx, cy, weatherIcon);
关于javascript - 嵌套属性的解构赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44083027/