如何在最新版本的BabelJS中启用对类属性的支持? [英] How to enable support for class properties in the latest version BabelJS?
本文介绍了如何在最新版本的BabelJS中启用对类属性的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在最新版本的BabelJS中启用对类属性的支持吗?
Does anyone know how to enable support for properties of a class in the latest version BabelJS?
import React from 'react';
import {Component} from 'react';
export default class Button extends Component {
constructor(){
super();
}
myProp = {}; // ERROR: /path/to/file/Button.jsx: Unexpected token (9:11)
render(){
return <div></div>;
}
}
推荐答案
在Babel 6中,您可以使用 syntax-class-properties
插件,只需安装:
With Babel 6, you use the syntax-class-properties
plugin, by installing it:
npm install babel-plugin-syntax-class-properties
并将其添加到您的.babelrc
:
{
"plugins": ["syntax-class-properties"]
}
这篇关于如何在最新版本的BabelJS中启用对类属性的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文