Parsing error: Unexpected token ReactJS Problem
Parsing error: Unexpected token ReactJS Problem
我是 ReactJS 的新手,我想从 Traversy Media 的视频教程中学习基础知识,并且我完全按照他必须做的方式应用代码。但是我被卡住了 in this part 因为我得到了一个无法像这样编译的错误:
这是我写的代码:
App.js
import React, { Component } from 'react';
import Todos from './components/Todos';
import './App.css';
class App extends Component {
state = {
todos: [
{
id: 1,
title: 'Take out he trash',
completed: false
},
{
id: 2,
title: 'Have a Dinner',
completed: false
},
{
id: 3,
title: 'Meeting with Boss',
completed: false
},
]
};
render() {
return (
<div className="App">
<Todos todos={this.state.todos} />
</div>
);
}
}
export default App;
Todos.js
import React, {Component} from 'react';
import TodoItem from './TodoItem';
class Todos extends Component {
render() {
return this.props.todos.map((todo) => (
<TodoItem/>
));
}
}
export default Todos;
TodoItem.js
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return{
<div>
<p>Hello</p>
</div>
}
}
}
export default TodoItem;
应该是
return(
<div>
<p>Hello</p>
</div>
)
对方法或变量使用大括号
TodoItem.js return 语句中存在语法错误。只需替换此代码
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return(
<div>
<p>Hello</p>
</div>
)
}
}
export default TodoItem;
应该是这样的-
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return(
<div>
<p>Hello</p>
</div>
)
}
}
export default TodoItem;
我是 ReactJS 的新手,我想从 Traversy Media 的视频教程中学习基础知识,并且我完全按照他必须做的方式应用代码。但是我被卡住了 in this part 因为我得到了一个无法像这样编译的错误:
这是我写的代码:
App.js
import React, { Component } from 'react';
import Todos from './components/Todos';
import './App.css';
class App extends Component {
state = {
todos: [
{
id: 1,
title: 'Take out he trash',
completed: false
},
{
id: 2,
title: 'Have a Dinner',
completed: false
},
{
id: 3,
title: 'Meeting with Boss',
completed: false
},
]
};
render() {
return (
<div className="App">
<Todos todos={this.state.todos} />
</div>
);
}
}
export default App;
Todos.js
import React, {Component} from 'react';
import TodoItem from './TodoItem';
class Todos extends Component {
render() {
return this.props.todos.map((todo) => (
<TodoItem/>
));
}
}
export default Todos;
TodoItem.js
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return{
<div>
<p>Hello</p>
</div>
}
}
}
export default TodoItem;
应该是
return(
<div>
<p>Hello</p>
</div>
)
对方法或变量使用大括号
TodoItem.js return 语句中存在语法错误。只需替换此代码
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return(
<div>
<p>Hello</p>
</div>
)
}
}
export default TodoItem;
应该是这样的-
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return(
<div>
<p>Hello</p>
</div>
)
}
}
export default TodoItem;