Part 4: HTTP&Axios
Step 1: fetch hostels from an API with AXIOS
When the HostelList component is created, fetch an API to return the hostels. API link: http://slides.maxpou.fr/vuejs-training/resources/hostels.json
If you don't know which event is the most appropriate, checkout the Lifecycle diagram.
Tip!:
- You can install axios like the following:
(there is also some examples on the GitHub readme)npm install axios
- You can store variable in
config/prod.env.js
file and access to this variable withprocess.env.NODE_ENV
. Check official documentation about Environment Variables. - You can use a lifecycle hook like this
export default { data () { return { // ... } }, created () { console.log('I just get mounted!') } }