Javascript使用class的静态属性
import React from 'react'; export default class ToolButton extends React.Component { static propTypes = { name: React.PropTypes.string }; render () { return ( <div></div> ); } }
上面的代码使用了 static propTypes, ES6原本不支持这种写法, 但是babel支持,需要使用"transform-class-properties"这个插件。
另外在使用eslint做校验的时候会报错‘Unexpected token’,原因是因为eslint本身不支持这种写法,需要使用babel-eslint。另外babel-eslint需要安装estraverse-fb。

浙公网安备 33010602011771号