Answer the question
In order to leave comments, you need to log in
Confirmation window in vue?
Hello. There are n-th number of actions with the API, the response to which is returned as . So, for example, overwriting item, we make a request, if it returns , then we make the next post request without problems, if true, then we need to display a modal with confirmation of the action. What is the best way to implement this logic? exists: true or false
/api/item/check/
exists: false
Answer the question
In order to leave comments, you need to log in
Why are you doing a redundant check action? Check the post immediately post. In case of an error, return false, in case of success - an array of attributes of the record.
It can just encapsulate this logic into a separate function and call it in different places...
Just for example:
sendWithCheck(action1,action2, params) {
this.$store.dispatch(action1, params)
.then(r => {
if(r.result) {
showConfirmMessage('textmessage', () => {
// this is confirm event handler just for example
this.$store.dispatch(action2)
})
} else {
this.$store.dispatch(action2)
}
})
}
If you use axios, then look towards interceptors
https://github.com/axios/axios#interceptors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question