介绍

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

相关文章:

  • 2021-10-17
  • 2021-09-14
  • 2021-08-25
  • 2022-02-21
  • 2021-09-15
  • 2021-12-12
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-09-03
相关资源
相似解决方案