I have an action
storeExpense(context, params){
axios.post('api/expenses', params)
.then( response => {
context.dispatch('getExpenses')
})
.catch( error => {
context.commit('errors', error.response.data.errors)
//console.log(error.response.data.errors);
})
}
and then on my component when the user click the submit button I just called the action via dispatch
store(){
this.$store.dispatch('storeExpense',this.expense)
}
Now i have sweetalert I'm confused how to implement it after a successful axios post request
I tried to put it inside my action like this
storeExpense(context, params){
axios.post('api/expenses', params)
.then( response => {
context.dispatch('getExpenses')
this.$swal(
'Success',
'Expense has been updated!',
'success'
)
})
.catch( error => {
context.commit('errors', error.response.data.errors)
//console.log(error.response.data.errors);
})
}
but nothing happened because it is on the action file. Should I call it inside my component like this?
this.$store.dispatch('storeExpense',this.expense)
.then( response => {
this.$swal(
'Success',
'Expense has been created!',
'success'
)
Any idea on how can I implement this? Thanks
Im beginner in vuejs and vuex.