【发布时间】:2020-09-08 11:14:06
【问题描述】:
我正在尝试使用 axios 调用我的数据库,但在我的 vsCode 终端中出现令人沮丧的错误。
这是错误:
SyntaxError: C:\Users\Kelly Owoju\Desktop\Kelly Bright\my-web-app\node_modules\axios\index.js: Unexpected character ' ' (1:0)
> 1 |
| ^
at parser.next (<anonymous>
这是我的代码:
import React, { Component } from 'react';
// import Typography from '@material-ui/core/Typography';
import { withStyles, createStyles } from "@material-ui/core/styles";
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Avatar from '@material-ui/core/Avatar';
import Menu from '../component/Menu';
import Typer from '../component/Typed';
import Show from '../component/Show'
import axios from 'axios';
// import Boxes from '../component/Boxes'
const styles = theme => createStyles({
avatar: {
[theme.breakpoints.down('lg')]: {
marginLeft: '150px'
},
[theme.breakpoints.down('md')]: {
marginLeft: '100px'
},
[theme.breakpoints.down('sm')]: {
marginLeft: '100px'
},
[theme.breakpoints.down('xs')]: {
marginLeft: '20px'
},
width: '60px',
height: '60px',
},
loading: {
textAlign: 'center'
}
})
class Home extends Component {
constructor() {
super()
this.state = {
slides: null
}
}
componentDidMount(){
axios.get('/slides').then(res => {
console.log(res.data);
this.setState({slides: res.data});
}).catch(e => {
console.error(e);
});
};
render() {
const {classes} = this.props;
let showSection = this.state.slides ? (
this.state.slides.map(slide => <Show slide={slide} key={slide.id} />)
): <p className={classes.loading} >Loading...</p>
return(
<>
<AppBar position='fixed' >
<Toolbar>
<Avatar
className={classes.avatar}
variant='circle'
src='logo.jpg'
/>
<Menu />
</Toolbar>
</AppBar>
{showSection}
<Typer />
</>
)
}
}
export default withStyles(styles)(Home);
请问有人可以帮我解决这个问题吗?我不知道问题可能是什么。我以前从来没有见过这个。谁知道呢,它甚至可能是一件微不足道的事情。但请帮帮我。谢谢
【问题讨论】:
标签: javascript node.js reactjs axios material-ui