JSFiddle - React, Tailwind, and code Playground

by imall

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.global.js"></script>
    <div id="app">
        <hello v-if="isShow" @click="isShow=!isShow"></hello>
    </div>

JavaScript

const { onBeforeUnmount, onUnmounted, ref } = Vue;
        var app = Vue.createApp({
            setup() {
                const isShow = ref(true)
                return {
                    isShow
                }
            }
        })
        app.component('hello', {
            template: `<div>你可以點我看看 onBeforeUnmount 跟 onUnmounted 的執行</div>`,
            setup() {
                onBeforeUnmount(() => {
                    console.log('onBeforeUnmount')
                })
                onUnmounted(() => {
                    console.log('onUnmounted')
                })
            }
        })
        app.mount('#app')