In all my Vue modules, I find myself repeating this code:
import axios from 'axios'
axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN'
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.withCredentials = true
Instead of repeating it, I'd like to do something like this:
import axios from './myaxios'
So, I attempted the following:
import axios from 'axios'
function myaxios () {
axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN'
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.withCredentials = true
return axios
}
export default myaxios
Unfortunately, it doesn't work as expected. What am I doing incorrectly?