1. 程式人生 > 其它 >Vue3的生命週期函式

Vue3的生命週期函式

<html>
    <head>
        <script src="https://unpkg.com/vue@next"></script>
    </head>
    <body>
        <div id="app">
            <button @click="show">{{message}}</button>
        </div>
    </body>
    <script>
        const app 
= Vue.createApp({ data(){ return { message: 'hello world!' } }, methods:{ show(){ alert('click'); } }, //Vue例項建立之前 beforeCreate(){ alert(
'before create'); }, //Vue例項建立完畢 created(){ alert('created'); }, //模板渲染之前 beforeMount(){ alert('beforeMount'); }, //模板渲染完畢 mounted(){ alert('mounted'); } }); app.mount(
'#app'); </script> </html>

beforeCreate     例項建立之前

createt       例項建立完畢

beforeMount    模板渲染之前

mounted      模板渲染完畢