Module not found: Can't resolve 'axios' in
Failed to compile
./src/components/Header/index.js
Module not found: Can't resolve 'axios' in 'D:\E-File\News\news\src\components\Header'
This error occurred during the build time and cannot be dismissed.
import React, { Component, Fragment } from 'react';
import { Menu, Icon } from 'antd';
import axios from 'axios';
import logo from './logo.png';
class AppHeader extends Component {
constructor(props) {
super(props);
this.state = {
list: []
}
}
getMenuItems() {
return this.state.list.map(item => {
return (
<Menu.Item
key={item.id}
icon={ item.icon }
>
{item.title}
</Menu.Item>
)
})
}
componentDidMount() {
axios.get('http://www.dell-lee.com/react/api/header.json')
.then((res) => {
this.setState({
list: res.data.data
})
})
}
render() {
return (
<Fragment>
<img src={logo} className='app-header-logo'/>
<Menu
mode="horizontal"
className='app-header-menu'
>
{ this.getMenuItems() }
</Menu>
</Fragment>
)
}
}
export default AppHeader;
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星