[Vuejs]-VueJS Axios Post Request – Can't update data binding

3👍

this.token inside function is not Vuejs instance. You should use arrow function for it

onSubmit(e) {
    e.preventDefault();
    this.token = "This works!"
    axios.post('http://mydomain/login', {
        username: this.form.email,
        password: this.form.password
    })
    .then((response) => {
        this.token = "This does not work!"
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });
}
👤ittus

Leave a comment