I have created an API call using axios and want to display it using Vue.js. But it doesn't display anything. Its like the elements are not rendered. I checked the elements console and the elements isn't there.
Code:
<div class="row" id="item-data">
<div class="col-lg-4 col-md-6" v-for="items in data" >
<a href="#" class="latest-product__item">
<div class="latest-product__item__pic">
<img src="img/latest-product/lp-1.jpg" alt="">
</div>
<div class="latest-product__item__text">
<h6>{{items.item_name}}</h6>
<div v-for="variant in items.variants">
<div v-for="store in variant.stores">
<span>{{store.price}}</span>
</div>
</div>
</div>
</a>
</div>
</div>
Vue.js Code:
window.onload = function () {
const access_token = "231231212412zcaqe";
new Vue({
el: '#item-data',
data () {
return {
data:[]
}
},
mounted () {
axios.get('https://cors-anywhere.herokuapp.com/https://api.loyverse.com/v0.7/items', {
headers : {
Authorization: 'Bearer ' + access_token
},
params: {
limit: 10
}
})
.then(function (response) {
// handle success
this.data = response.data.items
console.log(this.data);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
}
})
}