This theme is from C|

guangzan

园龄:6年5个月粉丝:676关注:333

2019-11-05 15:14阅读: 5242评论: 0推荐: 1

vue3生命周期

介绍

vue3的生命周期函数,可以按需导入到组件中,且只能setup() 函数中使用

示例

import { onMounted, onUpdated } from '@vue/composition-api'

export default {
    setup() {
        onMounted(() => {
        console.log('mounted')
        })
        onUpdated(() => {
        console.log('updated')
        })
    }
}
  

对比vue2.x

  • beforeCreate -> 使用setup()
  • created -> 使用 setup()
  • beforeMount -> onBeforeMount
  • mounted -> onMounted
  • beforeUpdate -> onBeforeUpdate
  • updated -> onUpdated
  • beforeDestroy -> onBeforeUnmount
  • destroyed -> onUnmounted
  • errorCaptured -> onErrorCaptured

本文作者:guangzan

本文链接:https://www.cnblogs.com/guangzan/p/11798596.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   guangzan  阅读(5242)  评论(0编辑  收藏  举报
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示