Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use created hook in setup script?

<script>
    export default {
        setup() {

        }
        created() {

        }
    }
</script>

When i change to use script setup syntax, how to use created hook ?

<setup script>
    // how to use created hook ?
</script>

like image 664
hewc Avatar asked Sep 16 '25 11:09

hewc


1 Answers

As you can see here, there is no such thing as created in Composition API lifecycle: https://vuejs.org/api/composition-api-lifecycle.html

Because it happens before the actual creation

All APIs listed on this page must be called synchronously during the setup() phase of a component. See Guide - Lifecycle Hooks for more details.

enter image description here

created hook coming just after as shown here: https://vuejs.org/guide/essentials/lifecycle.html#lifecycle-diagram

like image 54
kissu Avatar answered Sep 19 '25 06:09

kissu