Skip to content

Instantly share code, notes, and snippets.

@hex-ci
Last active November 17, 2017 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hex-ci/43dacac0c4183df821eada04064b1a62 to your computer and use it in GitHub Desktop.
Save hex-ci/43dacac0c4183df821eada04064b1a62 to your computer and use it in GitHub Desktop.
Axios with QueryString form data.
import axios from 'axios'
import qs from 'qs'
const axiosInstance = axios.create({
transformRequest: [function(data) {
return qs.stringify(data);
}],
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
}
})
// Send a POST request
axiosInstance({
method: 'post',
url: '/demo/12345',
data: {
key1: 'value1',
key2: 'value2'
}
}).then(function(response) {
console.log(response)
})
.catch(function(error) {
console.log(error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment