Last active
January 10, 2020 20:30
-
-
Save andregardi/50a019648afedc8eb93579410e82c709 to your computer and use it in GitHub Desktop.
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
<script src="https://unpkg.com/vue/dist/vue.min.js"></script> | |
<div id="main"> | |
<h1>Shopping cart</h1> | |
<p>Apples: {{ products.apple }}</p> | |
<p>Bananas: {{ products.banana }}</p> | |
<p>Oranges: {{ products.orange }}</p> | |
</div> | |
<script> | |
new Vue({ | |
el: "#main", | |
data: { | |
products: { | |
apple: 0, | |
banana: 0, | |
orange: 0 | |
} | |
}, | |
methods: { | |
add: function(event) { | |
this.products[event.data]++; | |
} | |
}, | |
beforeMount() { | |
window.addEventListener("message", this.add); | |
}, | |
beforeDestroy() { | |
window.removeEventListener("message", this.add); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment