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

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -