Skip to content

Instantly share code, notes, and snippets.

@cristijora
Last active July 11, 2019 19:07
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/79d6d170ee127deb680c1755d4d3065b to your computer and use it in GitHub Desktop.
Save cristijora/79d6d170ee127deb680c1755d4d3065b to your computer and use it in GitHub Desktop.
Mutate nested props
<template>
<div class="hello">
<div>Name: {{product.name}}</div>
<div>Price: {{product.price}}</div>
<div>Stock: {{product.stock}}</div>
<button @click="addToCart" :disabled="product.stock <= 0">Add to card</button>
</div>
</template>
<script>
export default {
name: "HelloWorld",
props: {
product: {
type: Object,
default: () => ({})
}
},
methods: {
addToCart() {
if (this.product.stock > 0) {
this.$emit("add-to-cart");
this.product.stock--;
}
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment