How to enable support for class properties in the latest version BabelJS?

蹲街弑〆低调 提交于 2019-12-25 05:55:03

问题


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>;
    }
}

回答1:


With Babel 6, you use the syntax-class-properties plugin, by installing it:

npm install babel-plugin-syntax-class-properties

and adding it to your .babelrc:

{
  "plugins": ["syntax-class-properties"]
}


来源:https://stackoverflow.com/questions/33980980/how-to-enable-support-for-class-properties-in-the-latest-version-babeljs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!