laravel 5 - VueJS: Uncaught (in promise) TypeError: Cannot read property 'push' of undefined -
i getting 'cannot read property push of undefined' error: here 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 doing wrong? thanks
this.coisignedlistuid
not defined
probably because this
not this
think is
you should do
var _this =
outside function , then
_this.coisignedlistuid.push(detail.uid);
alternatively, can use es2015 arrow syntax.
instead of:
.then(function (response) {}
use:
.then((response) => {}
the 'this' available inside function no need creating new variable. full details here.
Comments
Post a Comment