[Vuejs]-Setup function says object is not defined, even tough it is defined in the function and is being returned

0👍

newBlog is declared inside the onSubmit function, and it’s not accessible outside of that scope, leading to the error you observed.

To fix the issue, move the newBlog declaration outside onSubmit:

export default {
  setup() {
    //...

    const newBlog = {...}

    const onSubmit = (e) => {
      this.$emit('add-blog', newBlog)
    }

    return { title, body, onSubmit, newBlog }
  }
}

Leave a comment