我设置了一个普通的 create-react-app 项目并将 jsconfig.json 添加到根目录。但它显示了与打字稿相关的错误。
这是 jsconfig.json 文件
文件夹结构
谁能帮我这个?
谢谢,普拉希尔
javascript configuration typescript reactjs visual-studio-code
我正在使用 react Js 将图像上传到 django restframework。在这里,我使用 fetch API 发送 post 请求。
应用程序.jsx
import React, { Component } from 'react';
class Eapp extends Component {
constructor(props){
super(props);
this.state = {
profilePic: null,
};
this.inpuElement = null;
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e){
this.setState({profilePic: e.target.files[0]});
}
handleSubmit(){
let formData = new FormData();
formData.append('profile_pic',this.state.profilePic);
fetch('http://10.42.0.1:8000/auth/profile-pic/', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'content-type': 'multipart/form-data',
},
body:formData,
}).then(res => res.json())
.then((data) => {
console.log(data);
})
.catch(err => console.log(err));
}
render(){ …Run Code Online (Sandbox Code Playgroud)