Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vue] vue组件会在什么时候下被销毁? #445

Open
haizhilin2013 opened this issue Jun 22, 2019 · 6 comments
Open

[vue] vue组件会在什么时候下被销毁? #445

haizhilin2013 opened this issue Jun 22, 2019 · 6 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] vue组件会在什么时候下被销毁?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 22, 2019
@maozhuo123
Copy link

v-if=‘false‘

@Yanhua67
Copy link

Yanhua67 commented Aug 1, 2019

没有使用keep-alive时的路由切换。

@chenjinWeb
Copy link

路由跳转的时候!

@w245607930
Copy link

页面关闭、路由跳转、v-if和改变key值

@hyj443
Copy link

hyj443 commented Oct 27, 2021

v-if绑定的值变为falsy的时候

路由跳转,默认会销毁上一个组件,router.push、go、replace都会走销毁的钩子
如果想保留原组件数据,就加 包裹,会缓存不活动的组件实例,而不是销毁它们。

改变key值
vue的patch原理是要先判断新旧vnode是否描述的是同一个vnode,它是根据vnode的类型(即元素类型)和key值判断的,是同一个vnode,才会用diff算法进行比对更新
如果key改变了,那就意味着新旧vnode是两个独立不相同的组件,就会把旧的组件销毁,重新创建组件

@wanlixi
Copy link

wanlixi commented Apr 8, 2022

还有父组件销毁后子组件也会被销毁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

7 participants