What is the difference between mounted() and ionViewDidEnter()?

I was looking at a way to get get the reference to DOM elements in created() but it returned null. Then I found that you can do it with ionViewDidEnter(). There is also mounted() which I am thinking does the same thing so can someone please clarify?

Ionic caches views, and as such, components/views may not be re-rendered when navigated to more than once, and therefore mounted() or created() wouldn’t be called more than once (since they’re only called when the component/view is being rendered). ionViewDidEnter(), on the other hand, is called each time a view is routed to.

Also note that you cannot access the DOM in created() since it’s called before render (see image below), use mounted() instead, or ionViewDidEnter(), if you want to access the DOM again each time the view is navigated to.


The above answer is correct regarding Ionic lifecycle hooks. You can find more information on this at Vue Lifecycle - Ionic Documentation.

1 Like