So I'm using vue 2 for a project and I need to update an array that I named storychosen with the number of tests passed,failed and skipped for each story (I have a collection of tests that are grouped by story name) this is the method that I use to get that)
getstoryresult(storyname) {
const res=axios({
method: "post",
url: "http://localhost:3002/backend/storytests",
data: {
stname: storyname
},
}).then(function(result){
console.log(result.data.data)
var storypass=0
var storyfail=0
var storyskip=0
for (let i in result.data.data){
switch(result.data.data[i].status)
{
case 'passed':storypass++;break;
case 'skipped':storyskip++;break;
case 'failed':storyfail++;break;
}
}
console.log(storypass,storyfail,storyskip)
this.storychosen= [storypass, storyfail, storyskip] //storychosen is declared in data as an empty array
})
}
the post request return an array of tests and I just iterate over these tests and get the status of each test and increment one of the 3 status variables.
my problem is when i try to update the storychosen variable i get the error Uncaught (in promise) TypeError: Cannot set properties of undefined.I'm not used to working with promises so it might be a stupid question but how can I update the storychosen array in the .then function