Skip to content

Instantly share code, notes, and snippets.

@illepic
Forked from bleeDev/index.html
Last active October 31, 2017 15:23
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 illepic/af19a418a0b44a4fdbb0cbaed83be954 to your computer and use it in GitHub Desktop.
Save illepic/af19a418a0b44a4fdbb0cbaed83be954 to your computer and use it in GitHub Desktop.
jaPbeN
<html>
<body>
<div id="app">
<div>
{{ notes }}
</div>
<button @click='increase'>Increase</button>
<button @click='decrease'>Decrease</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.2/vue.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vuex/2.5.0/vuex.js" ></script>
<script>
var vstore = new Vuex.Store({
state: {
notes: 1
},
actions: {
increase: function actions(vueStuff, payload) {
vueStuff.commit('increase', payload)
},
decrease: function decrease(vueStuff, payload) {
vueStuff.commit('decrease', payload)
},
},
mutations: {
increase: function increase(state, payload) {
state.notes += payload
},
decrease: function decrease(state, payload) {
state.notes -= payload
}
},
getters: {
notes: function notes(state) {
return state.notes
}
}
});
/* ------------------------------------------ */
/* Vuex */
var vm = new Vue({
el: '#app',
store: vstore,
computed: {
notes: function notes() {
return this.$store.getters.notes;
}
},
methods: {
increase: function increase() {
this.$store.dispatch('increase', 1)
},
decrease: function decrease() {
this.$store.dispatch('decrease', 1)
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment