axios send file
var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
axios send file
var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
return axios response from seperate file
import axios from 'axios';
export function getData(config, callback, errorcallback){
axios.get(url, config)
.then(res => {
//do something
if(callback != null){
callback(res);
}
})
.catch(err => {
// catch error
if(errorcallback != null){
errorcallback(err);
}
})
}
In any component, use as follows
// get the location of your apicalls.js file and use to import like below
import { getData } from '../../routetothisjsfile'
//use it
var config = { "Access-Control-Allow-Origin": "*" }
getData(config, (res) => {
//success
},(err) => {
//error
alert(err);
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us