R
R
Roman2019-04-01 12:07:12
Vue.js
Roman, 2019-04-01 12:07:12

Why does it give an error when setting a property?

Good afternoon.
There is a feedback form on the site. Sending a request via axios.
It is necessary to display a window about successful sending after sending the request.
In data, I started the complete property, hung v-if on the block in the notification.
But for some reason there is an error
Cannot set property 'complete' of undefined

sendCart: function() {
                axios.post('/sendMessage', {
                        name: this.name,
                        phone: this.phone,
                        mail: this.mail
                    },
                )
                    .then(function (response) {
                        this.complete = true;
                    })
                    .catch(function (error) {
                        console.log(error)
                    });
            },

data: function() {
            return {
                name: "",
                phone: "",
                mail: "",
                complete: false
            }
        },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
ubx7b8, 2019-04-01
@roman94

Inside callbacks, this is no longer the same this )
first you need to store this in another variable, and then use it in callbacks
var vm = this
...
...function () {
vm.complete = true
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question