M
M
myskypesla2018-07-18 01:10:07
Vue.js
myskypesla, 2018-07-18 01:10:07

How to return a promise from another file?

Hello.
There is a login file with code

this.$store.dispatch('checkAuth')
  .then((response) => {
    console.log(response);
    // тут нужно получить true и залогинется
  })
  .catch((error) => {
    console.error(error);
  });

There is also another file store.js which has this code
this.dispatch('refreshToken')
  .then((response) => {
    console.log(response);
    // тут нужно получить true и отправить в предыдущую функцию
  })
  .catch((error) => {
    console.error(error);
  });

refreshToken() {
  axios.post(apiUrl, data)
    .then((response) => {
      console.log(response);
      // тут нужно получить true и отправить в предыдущую функцию
    })
    .catch((error) => {
      console.error(error);
    });
}

The question is how to pass the true value to the very first function from the second, and to the second from the third one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2018-07-18
@Fragster

return Promise resolve(true);
return Promise reject(true);
In general, I advise you to start with the documentation https://learn.javascript.ru/promise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question