setup相当于之前的created周期:创建时

onBeforeMount:DOM即将挂载

onMounted:DOM挂载完毕

onBeforeUpdate:DOM即将更新

onUpdated:DOM更新完毕

onBeforeUnmount:即将销毁

onUnmounted:销毁完毕

<script lang="ts">
import { defineComponent, onBeforeMount,onMounted } from 'vue'

//声明周期:vue3中名称发生了变更
//setup相当于之前的created周期:创建时
export default defineComponent({
  setup () {
    onBeforeMount(() => {
      console.log("DOM即将挂载");
    })
    onMounted(() => {
      console.log("DOM挂载完毕");
    })
    // onBeforeUpdate(() => {})    DOM即将更新
    // onUpdated(() => {})   DOM更新完毕
    // onBeforeUnmount(() => {})   即将销毁
    // onUnmounted(() => {})   销毁完毕
     

    return {}
  }
})
</script>
Logo

前往低代码交流专区

更多推荐