Fetch url with vue by await
02 February 2022
JavaScript
Web
Development
Vue
Handy way to fetch data by id from an url (for example from mockapi.io)
async mounted() {
this.fetchPlan(1);
},
methods: {
async fetchPlan(id) {
const getPlan = await fetch(
`https://xyz.mockapi.io/api/plan/${id}`
);
this.wCards = await getPlan.json();
},
}