http://codepen.io/JessieZhou/pen/VPgMdP,下面是一個使用作出反應CodePen演示,但是瀏覽器提供了一個錯誤「未捕獲的ReferenceError:組件沒有定義」。但是,如果我在第一行插入一行「從'react'」導入{Component},則錯誤將爲「Uncaught ReferenceError:require is not defined」。 'class'的使用是否有可能導致這個問題?如何Codepen使用與反應器ES6
這裏是我的代碼:
//import {Component} from 'react'
class MyInput extends Component{
constructor(props){
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e){
this.props.update(e.target.value);
}
render(){
return <input onChange={this.handleChange} type="text"/>
}
}
ReactDOM.render(MyInput, document.getElementById('myinput'));
這是我在CodePen JavaScript設置: javascript settings in codepen
非常感謝您!使用React.Component的工作,但如果我想使用組件,「進口{}組件從‘反應’」仍然沒有工作,錯誤的是「未捕獲的ReferenceError:要求沒有定義」 ...... – JessieZhou
使用這條線你的項目,它會工作,我們曾經使用lib鏈接的codepen,這就是爲什麼我們必須使用完整的React.Component。 –