vue3 中取消了,beforeCreate与 created 这两个生命周期函数,其他的生命周期函数也发生了改变。
图标中左侧是vue2中的名称,右侧是对应的vue3中的名称。
beforeMount | onBeforeMount |
mounted | onMounted |
beforeUpdate | onBeforeUpdate |
updated | onUpdated |
beforeDestory | onBeforeUnmount |
destoryed | onUnmounted |
使用方法上也有不同
在vue2中所有的生命周期函数都可以直接使用。
在vue3中一个生命周期函数需要先引用后使用,并且不能单独直接使用,要在setup()中使用。
export default {
setup() {
//在这里使用
}
}