react-es5转es6

Posted 一朵梨花压海棠 18802686535

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react-es5转es6相关的知识,希望对你有一定的参考价值。

import React,{Component} from ‘react‘;
import { Input } from ‘antd‘;
import lebab from ‘lebab‘;
import SyntaxHighlighter from ‘react-syntax-highlighter‘;
import { docco } from ‘react-syntax-highlighter/dist/styles‘;
class Demo extends Component {
    constructor(props) {
        super(props);

        this.state = {
            data:‘var a = {}‘
        };
    }
    componentDidMount(){
        const {code, warnings} = lebab.transform(this.state.data,
            [‘let‘,‘class‘, ‘arrow‘,‘template‘,‘default-param‘,‘destruct-param‘,‘includes‘,‘for-of‘,‘for-each‘,‘arg-rest‘,‘arg-spread‘,‘obj-method‘,‘commonjs‘,‘exponent‘,‘multi-var‘]
        );
        this.setState({data:code})
    }
    handleChange=(e)=>{
        const {code, warnings} = lebab.transform(e.target.value,
            [‘let‘,‘class‘, ‘arrow‘,‘template‘,‘default-param‘,‘destruct-param‘,‘includes‘,‘for-of‘,‘for-each‘,‘arg-rest‘,‘arg-spread‘,‘obj-method‘,‘commonjs‘,‘exponent‘,‘multi-var‘]
        );
        this.setState({data:code})
    };
    render() {
        return (
            <div>
                <div className="content">
                    <h3>输入</h3>
                    <Input onChange={this.handleChange} defaultValue="var a = {}" type="textarea" autosize={{minRows:8}} />
                </div>
                <div className="content">
                    <h3>输出</h3>
                    <SyntaxHighlighter language=‘javascript‘ style={docco}>{this.state.data}</SyntaxHighlighter>
                </div>
            </div>
        );
    }
}
export default Demo

  

以上是关于react-es5转es6的主要内容,如果未能解决你的问题,请参考以下文章

Angular vs React---React-ing to change

很实用的JQuery代码片段(转)

30秒就能看懂的JavaScript 代码片段

几个有用的JavaScript/jQuery代码片段(转)

vue2.0 代码功能片段

实用代码片段将json数据绑定到html元素 (转)