A
A
Artem00712017-04-25 01:27:46
Vue.js
Artem0071, 2017-04-25 01:27:46

When to use mounted and when to use created?

Decided to take a closer look at Vue.
Can someone explain in what cases it is necessary to use created, mounted and the rest?
Let's say I have data from the server.
In which method should I place a function to download information from the server?
And, if possible, it would be nice to know this for all methods, at least with approximate examples. But the documentation only says:

Below is a diagram of the life cycle of an instance. You don't need to fully understand it now, but it will come in handy in the future.

scheme
074941eb59f349de8a333cec1fa0fd89.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-04-25
@ber_enot

The data loading function is usually placed in mounted(), because you need to display some kind of preloader, and after loading the data - show them too.
The created() event is called when the component is created, but not yet placed in the DOM (in other words, you only <div id="app"></div>have , and there is nowhere to show information on the page.
More details are written in the documentation in the API section:
https://ru.vuejs. org/v2/api/#created

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question