ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

什么是Vue的生命周期 ?

2026/9/15 19:45:37 拓冰建站 浏览量
什么是Vue的生命周期 ?

使用最多的:

  1. created:进行axios
  2. mounted:挂载元素内dom节点的获取;

新老版本生命周期对比

 

区别:

Componsition API中,生命周期是从vue中导出的,需要用到的要进行导入,setup除外

除setup外,其他的生命周期都是写在setup中

setup函数是发生在beforeCreate之前的

写法:

import {onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, onUpdated
} from "vue";
export default {setup() {onBeforeMount(() => {//执行函数});onMounted(() => {//执行函数});onBeforeUpdate(() => {//执行函数});onUpdated(() => {//执行函数});onBeforeUnmount(() => {//执行函数});onUnmounted(() => {//执行函数});}
};