I am a little confused on when to use the "this" word in vue.js. For example, in the code below everywhere I use "vm" instead of "this" the code does not work.
I have also seen some examples using "self", however I am not a javascript guru and this is really confusing.
var vm = new Vue({
el: '#app',
data: {
tickets: [],
top: 100,
search: '',
showAdd: false,
},
mounted: function () {
this.$nextTick(function () {
console.log('mounted');
this.GetTickets(100);
})
},
methods: {
GetTickets: function (top) {
axios.get('/api/Tickets', {
params: {
Top: top
}
})
.then(function (response) {
vm.tickets = response.data;
})
.catch(function (error) {
console.log(error);
});
},
ClearTicket: function () {
var t = {
"ticketSubject": '',
"contactName": '',
"createdAt": moment()
}
vm.ticket = t;
vm.showAdd = !vm.showAdd;
},
AddTicket: function () {
//vm.tickets.unshift(vm.ticket);
axios.post('/api/Tickets', vm.ticket)
.then(function (response) {
console.log(response);
vm.GetTickets(100);
})
.catch(function (error) {
console.log(error);
});
vm.showAdd = false;
}
},
})