Vue3的生命周期有一点和2不同

70 阅读1分钟

最后两个beforeUnmount和unmounted与vue2的beforeDestory和destoryed

<template>
  <div>
    {{ testval }}
    <button @click="clickMe">点我</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      testval: "testval",
    };

  },
  methods: {
    clickMe() {
      this.testval = "testval2";
    },

  },
  beforeCreate() {
    console.log("beforeCreate");
  },
  created() {
    console.log("created");
  },

  beforeMount() {
    console.log("beforeMount");
  },
  mounted() {
    console.log("mounted");
  },

  beforeUpdate() {
    console.log("beforeUpdate");
  },

  updated() {
    console.log("updated");
  },
  beforeUnmount() {
    console.log("beforeUnmount");
  },
  unmounted() {
    console.log("unmounted");
  },
};
</script>

<style></style>