docs icon indicating copy to clipboard operation
docs copied to clipboard

Lifecycle diagram `unmounted` => `onUnmounted`

Open orionna319 opened this issue 1 year ago • 7 comments

lifecycle-diagram

Thanks to the community for their contribution. When I used the documentation, I found that the flow chart was inconsistent with the actual situation.

unmounted => onUnmounted

image

orionna319 avatar Jan 26 '24 12:01 orionna319

Why? I think it's consistent with the naming of other things that are mentioned there like mounted, beforeMount, updated, beforeUpdate... onUnmounted is the hook, unmounted is the event.

brc-dd avatar Jan 26 '24 12:01 brc-dd

onUnmounted is the hook, unmounted is the event, you are correct.

When I was not very familiar with Lifecycle Hooks, I would look at this flow chart, because mounted is a hook in vue2, so I would think that unmounted is also a hook, and then I would import { unmounted } from 'vue', which confuses me

onUnmounted is the hook, unmounted is the event.

orionna319 avatar Jan 26 '24 12:01 orionna319

Ah, actually if you're using options API, it's still unmounted:

export default {
  unmounted() {
    // ...
  }
}

If you read that page completely, then the section above that image shows the usage (depending on your choice of options/compositions API).

event might be wrong technical term in my earlier comment. I believe it's more like onUnmounted is for composition API, unmounted is for options API. And the diagram explicitly mentions options API.

brc-dd avatar Jan 26 '24 12:01 brc-dd

So the text described by the red border in the lifecycle-diagram is a hook, but it is a hook for the options API. Since the composition API is officially recommended, can we have a lifecycle-diagram corresponding to the options API and composition API?

The API Preference in the current document defaults to the composition API, and lifecycle-diagram displays the options API hooks. When we switch the API Preference, it may be better to display the lifecycle-diagram corresponding to the hooks.

orionna319 avatar Jan 26 '24 13:01 orionna319

When we switch the API Preference, it may be better to display the lifecycle-diagram corresponding to the hooks.

@orionna319 This is a great suggestion! I'll take a look at how we can implement this.

bencodezen avatar Jan 30 '24 17:01 bencodezen

@orionna319 Sorry for the delay on this. Currently working on the best way to explain this, but what do you think of this draft diagram?

lifecycle-composition

bencodezen avatar Apr 23 '24 17:04 bencodezen

Amazing work. Thank you very much for your contribution, which allows us to better understand composition-api-lifecycle. I'm sorry to reply to you a few days late. I have a question here, onCreated It seems that it is not in composition-api-lifecycle, in the official document.

orionna319 avatar Apr 25 '24 04:04 orionna319