vuejs 3 Error: Unexpected side effect in computed property

Cecil Migayi
Mar 29, 2021

--

So recently i had this error when working with Vue 3.

Here is how i had written my code:

data() {

return {submissions : []};

},

computed: {

sortedSubmissions() {

return this.submissions.sort((a,b) => {

return b.votes — a.votes;

});

}

},

};

Solution is to sort as follows:

return […this.submissions].sort((a,b) => {

return b.votes — a.votes;

});

For more info on this kindly check this link:

https://stackoverflow.com/questions/56819946/unexpected-side-effect-in-sortitem-computed-property

--

--

Cecil Migayi
Cecil Migayi

Written by Cecil Migayi

Software Engineer | Philosophy | Writing

No responses yet