Skip to content
Advertisement

How to return variable from Axios Response in Composition API to root level?

I want to return the headings array from an axios.get function and use it on root level inside my vue component but when I try to return it, it shows:

JavaScript

This is the script element from my Vue3 Component:

JavaScript

Edit:

Thanks to Thomas and huan feng I can do this:

JavaScript

This is the most elegant solution because reactive objects provide the cleanest framework when working with arrays. Call it from the vue component like so:

JavaScript

Since axios is asynchronous returning the variable into root level is more difficult and in my case not necessary. I can output it inside then.

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement