Vue: component calls update hook after it is destroyed

Created on 24 Apr 2018  ·  7Comments  ·  Source: vuejs/vue

Version

2.5.2

Reproduction link

https://codesandbox.io/s/ympx4pk72z

Steps to reproduce

1、click the home link
2、click the test link

What is expected?

after the Home component destroyed,its updated hook should not be called

What is actually happening?

after the Home component destroyed,its updated hook is called


here is the log information

Home beforeCreate
Home created
Home beforeMount
Home mounted
Test beforeCreate
Test created
Test beforeMount
Home beforeDestroy
Home destroyed
Test mounted
Home updated

why the Home component can call updated hook after it is destroyed?
Is Vue designed to do so?

bug has PR

Most helpful comment

@mbj36 Thank you for your reply. But I didn't perform any DOM-dependent operations when the updated hook was called.And according to Vue lifecycle,after one component is destroyed,its updated hook shouldn't be called.But in my repo,this condition happens.I can't figure out how this happens.

All 7 comments

@BL-Lac149597870 In your reproduction link, you have not defined your components as .vue component.

@mbj36 my bad.Now i have just corrected the mistake and changed the repo link,but the problem still remains...

@BL-Lac149597870 It's always better to use computed property or watcher - See the api docs here - https://vuejs.org/v2/api/#updated

@mbj36 Thank you for your reply. But I didn't perform any DOM-dependent operations when the updated hook was called.And according to Vue lifecycle,after one component is destroyed,its updated hook shouldn't be called.But in my repo,this condition happens.I can't figure out how this happens.

Met this problem, too.
Any news for this?😂
@BL-Lac149597870

@shockw4ver Maybe we can work it out together,hahaha~

I hate to bring bad news, but the fix only triggers the update part of the lifecycle, leaving beforeUpdate still being invoked after the component is destroyed.

Use the sandbox above with "vue": "^2.5.18-beta.0", to verify
(xposted on the PR accepted)

Was this page helpful?
0 / 5 - 0 ratings