L
L
lavezzi12018-04-03 06:46:57
Vue.js
lavezzi1, 2018-04-03 06:46:57

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

3 answer(s)
A
Anton, 2018-04-03
@karminski

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.

E
Evgeny Kulakov, 2018-04-03
@kulakoff Vue.js

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)
     }
  })
}

M
Maxim Markin, 2018-04-04
@owl1n

If you use axios, then look towards interceptors
https://github.com/axios/axios#interceptors

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question