Created
August 1, 2018 06:31
-
-
Save rahman541/a25ac436cdcb6266b1f2c016d6ac9a0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div id="app"> | |
{{ welcome }} | |
<h2>{{ message }}</h2> | |
<h3>{{ count }}</h3> | |
<button @click="pressed">Increment Counter</button> | |
</div> | |
<script src="https://unpkg.com/[email protected]"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | |
<script> | |
Vue.use(Vuex); | |
const store = new Vuex.Store({ | |
state: { | |
message: 'Hello from Vuex', | |
count: 0 | |
}, | |
mutations: { // syncronous | |
increment(state, payload) { | |
state.count+=payload | |
} | |
}, | |
actions: { // asynchronous | |
increment(state, payload) { | |
state.commit('increment', payload) | |
} | |
}, | |
getters: { | |
message(state) { | |
return state.message.toUpperCase(); | |
}, | |
counter(state) { | |
return state.count | |
} | |
} | |
}); | |
new Vue({ | |
el: '#app', | |
data: { | |
welcome: 'Hello World', | |
}, | |
computed: { | |
message() { | |
return store.getters.message; | |
}, | |
count() { | |
return store.getters.counter; | |
} | |
}, | |
methods: { | |
pressed() { | |
store.dispatch('increment', 10) | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment