react组件接收道具,而我正在这样分解它:
const { ram, core } = this.props;
但是我想将ram
的值除以1024
,当然可以:
let { ram, core } = this.props;
ram /= 1024;
我可以在一行中也可以使用const吗?
答案 0 :(得分:1)
您可以这样做:
const { ram, core } = ( ({ ram, core }) => ({ ram: ram/1024, core }) )(this.props);
const props = { ram: 2048, core: 7 };
const { ram, core } = ( ({ ram, core }) => ({ ram: ram/1024, core }) )(props);
console.log(ram);