Fetch url with vue by await - and reach an array
04 February 2022
JavaScript
Web
Development
Vue
Handy way to fetch data by id from an url (for example from mockapi.io) and reach an array as an endpoint
async mounted() {
this.fetchPlan(1);
},
methods: {
async fetchPlan(id) {
const getPlan = await fetch(
`https://xyz.mockapi.io/api/plan/${id}`
);
const card = await getPlan.json();
this.wCars = (cars[0]) ? cars[0].w_lessons : null;
},
}