Skip to content

Instantly share code, notes, and snippets.

@cristijora
Last active July 11, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristijora/2b6b6119a4ac78af5e86893911eb47fd to your computer and use it in GitHub Desktop.
Save cristijora/2b6b6119a4ac78af5e86893911eb47fd to your computer and use it in GitHub Desktop.
Mutating props
<template>
<Product :product="product" @add-to-cart="addProductToCart(product)"></Product>
</template>
<script>
import Product from "./components/Product";
export default {
name: "App",
components: {
Product
},
data() {
return {
product: {
name: "Laptop",
price: 1250,
stock: 2
}
};
},
methods: {
addProductToCart(product) {
if (product.stock > 0) {
product.stock--;
}
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment