找不到模块:无法解析'F:\ React \ react-complete-guide \ src \ Component'中的'../axios' [英] Module not found: Can't resolve '../axios' in 'F:\React\react-complete-guide\src\Component'
本文介绍了找不到模块:无法解析'F:\ React \ react-complete-guide \ src \ Component'中的'../axios'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 React
项目中遇到此编译错误,在该项目中我尝试发送 GET
请求:
I'm getting this compilation error in my React
project where I try to send a GET
request:
./src/Component/Form.js
Module not found: Can't resolve '../axios' in 'F:\React\react-complete-guide\src\Component'
代码:
import React, {Component} from 'react';
import axios from '../axios';
class Form extends React.Component{
state={UserName:""};
onChangeHandle=(event)=>{
this.setState({UserName:event.target.value});
}
handleSubmit= (event) =>{
event.preventDefault();
console.log('form submit');
axios.get('https://api.github.com/users/${this.state.UserName}')
.then(
resp=>{
console.log(resp);
})
};
render(){
return(
<form onSubmit={this.handleSubmit}>
<input type="text"
placeholder="Github UserName"
value={this.state.UserName}
onChange={this.onChangeHandle} />
<br/>
<button type="submit"> Add card </button>
</form>
)}
}
export default Form;
推荐答案
尝试:
1.使用 npm 安装 axios 模块: npm install axios --save
2..替换您的导入代码:从'../axios';
导入axios使用以下代码:从'axios'导入axios;
2. Replacing your import code: import axios from '../axios';
with the: import axios from 'axios';
这篇关于找不到模块:无法解析'F:\ React \ react-complete-guide \ src \ Component'中的'../axios'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文