JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vuex/3.1.0/vuex.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<div id="app">
<button @click="save()">Save</button>
</div>
JavaScript
const store = new Vuex.Store({
actions: {
async getTodo() {
try {
const res = await axios.get('https://jsonplaceholder.typicode.com/sgasgasgasg')
return res
} catch(e) {
console.log(e)
}
}
}
})
new Vue({
el: '#app',
store,
methods: {
async save() {
try {
await this.$store.dispatch('getTodo')
console.log('Request Completed')
} catch(e) {
console.log(e)
}
}
}
})