I have a modal with data from Vue.js, what I want to accomplish is, whenever the "add cart" button is clicked, the data inside the modal is saved to another array(itemCart) inside vue.
Vue.js:
new Vue({
el: '#item-data',
data () {
return {
data:[],
selectedUser:'',
itemCart: ''
}
},
mounted () {
axios.get('api link here', {
headers : {
Authorization: 'Bearer ' + access_token
},
params: {
limit: 250
}
})
.then((response) => {
// handle success
this.data = response.data.items
removeLoader();
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
},
methods:{
sendInfo(items) {
this.selectedUser = items;
},
addCart: function(cartItems){
this.itemCart.push({cartItems});
console.log(cartItems);
}
}
})
Modal:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<a href="#" class="latest-product__item">
<div class="latest-product__item__pic">
<img src="img/item_image_placeholder.jpg" alt="">
</div>
<div class="latest-product__item__text">
<span>{{selectedUser.item_name}}</span>
<div v-for="variant in selectedUser.variants">
<h6>Php {{variant.default_price}}/piece</h6>
</div>
<div class="product__details__quantity">
<div class="quantity">
<div class="pro-qty">
<input type="text" value="1">
</div>
</div>
</div>
</div>
</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success btn-block" @click="addCart">Add to Cart</button>
</div>
</div>
</div>
</div>
I have tried placing v-model inside the input tag in the modal, but i get an error that says its not defined on the instance. How do I achieve this?
cartItemscoming from?