S
S
SleepGame2019-05-28 11:15:53
Vue.js
SleepGame, 2019-05-28 11:15:53

Issue with Vue.js, [Vue warn]: Error in render?

Good afternoon,
There is a problem with Vue rendering, when executing the code below, it gives an error, but at the same time it executes it.
The code

computed: {
            //TODO: vue ругается на sort
            sortedArray() {
                return this.tasks.sort((a, b) => a.completed - b.completed )
            }
        },

Mistake
[Vue warn]: Error in render: "TypeError: this.tasks.sort is not a function"

How to remove the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ihor Bratukh, 2019-05-28
@SleepGame

this.tasks is not an array Rethink
your code
Crutch variant

if (!this.tasks) return [];
return this.tasks.sort((a, b) => a.completed - b.completed)

For solution without crutches show more code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question