设置状态表达不像往常一样



我正在阅读反应文档,无法理解这段代码:

handleFahrenheitChange(temperature){
    this.setState({
        scale:'f',
        temperature
    });
}

为什么它只是"温度"?它改变了什么?谢谢。

在 ES6 语法中你可以使用

{ temperature }

代表

{ temperature: temperature }

它与 React 完全无关。

温度是 es6 增强对象文字

http://www.benmvp.com/learning-es6-enhanced-object-literals/

温度是 ES6 增强的对象

https://facebook.github.io/react/docs/react-component.html

相关内容

最新更新