TypeError: {(intermediate value)(intermediate value)}.then is not a function
15,936
Solution 1
You need to move .then()
to the outside of .post()
. Try this:
methods: {
onSubmit: function () {
axios.post('/user_token', {
auth: {
email: this.$refs.user_email.value,
password: this.$refs.user_password.value
}
}).then(response => {
localStorage.setItem("token", response.data.jwt)
}).catch(error => {
var err = error.response.data.errors
});
}
}
Solution 2
Closing brace and parethese for axios.post
should come before .then
Author by
Bitwise
Updated on June 04, 2022Comments
-
Bitwise almost 2 years
I'm getting a strange error when trying to post with Axios.
JS:
methods: { onSubmit: function () { axios.post('/user_token', { auth: { email: this.$refs.user_email.value, password: this.$refs.user_password.value } .then(response => { debugger localStorage.setItem("token", response.data.jwt) }) .catch(error => { var err = error.response.data.errors }) }); } }
When submitting an email and password that are vaild I don't hit that debugger, instead I see this error in the console:
TypeError: {(intermediate value)(intermediate value)}.then is not a function
Anyone know what I'm doing wrong?
-
John Montgomery about 6 yearsYou need to move it outside the closing parenthesis for
post
, I'm pretty sure. -
Jaromanda X about 6 years
} .then
->}) .then
-