Javascript 嵌套属性的解构赋值

Javascript 嵌套属性的解构赋值,javascript,ecmascript-6,Javascript,Ecmascript 6,我需要从对象this.props.payload获取3个变量cx、cx和weatherIcon,当前我正在使用此代码 const { cx, cy } = this.props const {weatherIcon} = this.props.payload 它可以工作,但我想知道是否可以用一行书写。试试这个 const { cx, cy, payload: { weatherIcon } } = this.props; constprops={cx:1,cy:2,负载:{weatherI

我需要从对象
this.props.payload
获取3个变量
cx
cx
weatherIcon
,当前我正在使用此代码

const { cx, cy } = this.props
const {weatherIcon} = this.props.payload
它可以工作,但我想知道是否可以用一行书写。

试试这个

const { cx, cy, payload: { weatherIcon } } = this.props;
constprops={cx:1,cy:2,负载:{weatherIcon:3};
const{cx,cy,payload:{weatherIcon}}=props;
控制台日志(cx、cy、weatherIcon)试试这个

const { cx, cy, payload: { weatherIcon } } = this.props;
constprops={cx:1,cy:2,负载:{weatherIcon:3};
const{cx,cy,payload:{weatherIcon}}=props;
控制台日志(cx、cy、weatherIcon)