2

I created a Vue component. And in this component, I use axios to send post request when it's mounted, CSRF token also included, but still got 400 status. Anyone know why?

1 Answer 1

3

Just found the solution:

npm install qs

and

import qs from 'qs'

...
const actions = {
    auth({ commit }, { email, password }) {

        axios.post('url', qs.stringify({
            your token data here
        })).then((res) => {
            console.log(res.data)
        }).catch((err) => {
            console.log(err)
        })
    }
}
1
  • This was really helpful but I had to capitalize the Q in Qs.stringify() since I wasn't bundling the library with my other js code. If you want a full example of this in action using Vue and Axios, go here: craftcms.stackexchange.com/a/30713/4433
    – Ryan
    Jun 21, 2019 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.