I am getting the 'cannot read property push of undefined' error: here is my vueJs code:
data:{
CoIsignedListUID:[]
}
methods:{
fetchCoISigned: function () {
this.$http.get('/cimsm/public/api/fetchCoIsigned/' + this.conflictofInterest.complaintID).then(function (response) {
var data = response.data;
this.$set('CoIsignedList', data);
data.forEach(function (detail) {
this.CoIsignedListUID.push(detail.uID);
});
});
what am i doing wrong? Thanks
this.CoIsignedListUID
is not defined
probably because this
is not the this
you think it is
you should do
var _this = this
outside the function and then
_this.CoIsignedListUID.push(detail.uID);
Alternatively, you can use ES2015 arrow syntax.
Instead of:
.then(function (response) {}
Use:
.then((response) => {}
The 'this' is now available inside the function so no need for creating a new variable. Full details Here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With