马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
015 生命周期
组件的生命周期:
【时刻】 【调用特定的函数】
vue2生命周期
创建 beforeCreate、 created
挂载 beforeMounte、mounted
更新 beforeUpdate、updated
烧毁 beforeDestroy、destroyed
生命周期、生命周期函数、生命周期钩子
vue3生命周期
创建 setup
挂载 onBeforeMounte、onMounted
更新 onBeforeUpdate、onUpdated
烧毁 onBeforeUnmounte、onUnmounted
- <template>
- <div>
- <h2>当前求和{{ sum }}</h2>
- <button @click="addFn">点我sum+1</button>
- </div>
- </template>
复制代码- <script setup lang="ts" name="person">
- import { ref, onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted } from 'vue'
- // 数据
- let sum = ref(0);
- // 方法
- function addFn() {
- sum.value++;
- }
- // 创建
- console.log("创建");
- // 挂载前,调用onBeforeMount中的回调函数
- onBeforeMount(() => {
- console.log("挂载前");
- });
- onMounted(() => {
- console.log("挂载完毕");
- })
- // 更新前
- onBeforeUpdate(() => {
- console.log("更新前");
- })
- // 更新后
- onUpdated(() => {
- console.log("更新后");
- })
- // 卸载前
- onBeforeUnmount(() => {
- console.log("卸载前");
- })
- // 卸载后
- onUnmounted(() => {
- console.log("卸载后");
- })
- </script>
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |