Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

vue3 It seems that the setup function returns before the onMount function

createApp({
    setup() {
        let price = 0
    
        onMounted() {
            // axios
            price = axios.response
        }
        return { price }
    }
}).mount('#app')

HTML

<h6 id="app" class="mb-0">{{price}}</h6>

The current situation is that a value of 0 is continuously output.
Looking at the order, it seems that the setup function returns before the onMounted function and has already done the rendering.

What should I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should use price = ref(0) for reactivity.

https://vuejs.org/api/composition-api-setup.html#basic-usage

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading