[Vuejs]-Vue 3 data.name from api is undefined in script setup() but rendered in template

0👍

If you want to print a computed property in the setup function you have to access it with console.log(data.value.name).

In the template it’s working, because it automatically resolves to data.value if you render it via {{ data }}

Check the documentation to learn more: https://v3.vuejs.org/guide/composition-api-introduction.html#standalone-computed-properties

0👍

The solution was:

onUpdated(() => {
      console.log(data.value.name)
    })

It is no longer undefined and returns the value from the api

Leave a comment