[Vuejs]-Vue "Is not a function" problem in my todolist app

0👍

My guess is that the items that you get from the database in mounted are not instances of Todo class. Although you return them with todoList as Todo[], they are just raw data. These objects won’t have the toggleChecked method defined on them.

You could create Todo type objects from the retrieved data with something like this:

async function getTodo(db: Firestore) {
    // ...
    const todoList = todoSnapshot.docs.map(doc => {
        // pass 'todo' and 'checked' properties from doc to Todo
        return new Todo(doc.todo, doc.checked); 
    }

    return todoList as Todo[];
}

Leave a comment