I'm able to use fetch api (wanted to do the fetch api rather than axios) and call out my local api and console.log the data from my api.js file -
export default {
async getData(){
await fetch(url+"campground")
.then(result => result.json())
.then(data => {
console.log(data) // [{id:123,name:"Shimla"},{id:124,name:"Manali"}]
return data
})
}
}
The issue arises when I try to do it on my Catalogue.vue file.
<script>
import api from '../api';
export default {
name: 'Catalogue',
data() {
return {
camps: null
}
},
methods: {
},
created() {
this.camps = api.getData()
console.log(this.camps) //Promise { <state>: "pending" }
},
}
</script>
The result that I get is usually
Promise { : "pending" }
How can I proceed from here? Thank You