我试着从React开始,按照firebaseBlog上的例子,我试着运行以下代码,我得到了,
Uncaught SyntaxError: http://localhost/h/js/test.js: Unexpected token (1:28)
> 1 | componentWillMount: function() {
| ^
2 | this.firebaseRef = firebase.database().ref("items");
3 | this.firebaseRef.on("child_added", function(dataSnapshot) {
4 | this.items.push(dataSnapshot.val());所引用的代码是这样的。
componentWillMount: function() {
this.firebaseRef = firebase.database().ref("items");
this.firebaseRef.on("child_added", function(dataSnapshot) {
this.items.push(dataSnapshot.val());
this.setState({items: this.items});
}.bind(this)
);
} 发布于 2017-02-18 19:34:00
如果您的组件声明扩展了React.Component,如下所示...
class TestComponent extends React.Component {
...
}那么您的componentWillMount()和其他函数应该是这样的……
componentWillMount() {
...
}https://stackoverflow.com/questions/42312183
复制相似问题