Last active
July 11, 2019 15:55
-
-
Save cristijora/2b6b6119a4ac78af5e86893911eb47fd to your computer and use it in GitHub Desktop.
Mutating props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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