I have written an axios POST request as recommended from the npm package documentation like:
var data = {
\'key1\': \'val1\',
\'key2\': \'val2\'
}
ax
Or, if you are using some property from vuejs prototype that can't be read on creation you can also define headers and write i.e.
storePropertyMaxSpeed(){
axios.post('api/property', {
"property_name" : 'max_speed',
"property_amount" : this.newPropertyMaxSpeed
},
{headers : {'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.$gate.token()}})
.then(() => { //this below peace of code isn't important
Event.$emit('dbPropertyChanged');
$('#addPropertyMaxSpeedModal').modal('hide');
Swal.fire({
position: 'center',
type: 'success',
title: 'Nova brzina unešena u bazu',
showConfirmButton: false,
timer: 1500
})
})
.catch(() => {
Swal.fire("Neuspješno!", "Nešto je pošlo do đavola", "warning");
})
}
},
This might be helpful,
const data = {
email: "me@me.com",
username: "me"
};
const options = {
headers: {
'Content-Type': 'application/json',
}
};
axios.post('http://path', data, options)
.then((res) => {
console.log("RESPONSE ==== : ", res);
})
.catch((err) => {
console.log("ERROR: ====", err);
})
Blockquote
Blockquote
To set headers in an Axios POST request, pass the third object to the axios.post() call.
const token = '..your token..'
axios.post(url, {
//...data
}, {
headers: {
'Authorization': `Basic ${token}`
}
})
To set headers in an Axios GET request, pass a second object to the axios.get() call.
const token = '..your token..'
axios.get(url, {
headers: {
'Authorization': `Basic ${token}`
}
})
Cheers!! Read Simple Write Simple