Akryum / packt-vue-project-guide

Vue Project Guide Book Sources
https://www.packtpub.com/web-development/vuejs-2-web-development-projects
42 stars 37 forks source link

chp 2 selectedNote() #2

Closed mythicalprogrammer closed 6 years ago

mythicalprogrammer commented 6 years ago

It should be

computed: {
    selectedNote() {
        if(!this.notes.length) {
            this.addNote()
        }
        return this.notes.find(note => note.id === this.selectedId)
    }
}

If the notes array is empty then the selectedNote() function returns undefined and vuejs won't render. The ifcondition was added.

mythicalprogrammer commented 6 years ago

Nevermind, I should have read ahead sorry.