2π
β
-
Create
itemsCount
property on your componentβs data object:data: function { return { itemsCount: "" } }
-
Use
v-model
attribute to assign the value of your input to theitemsCount
property.<input type="number" class="col-1 form-control" v-model="itemsCount" />
-
Refactor
addToCart()
function to takeitemsCount
value into account.addToCart() { let quantity = this.itemsCount !== "" ? this.itemsCount : 1 this.$store.dispatch('addProductToCart', { product: this.product, quantity: parseInt(quantity) }) }
π€user14967413
1π
Have you considered something like this?
<input type="number" v-model="quantity" />
And later your method
addToCart() {
this.$store.dispatch("addProductToCart", {
product: this.product,
quantity: this.quantity // this.quantity here
});
}
π€vch
Source:stackexchange.com