F
F
frolova_elena2018-07-23 10:57:14
Vue.js
frolova_elena, 2018-07-23 10:57:14

How to properly implement a double request?

methods: {
    signin() {
      // this.$root.$emit('loading', true);
      axios.all([
        axios.post('auth/signin', {
          user: {
            email: this.email,
            password: this.password,
          }
        }),
        axios.get("captcha/check", {
          captcha: this.captcha
        })
      ]).then(res => {
        console.log(res.data.user);
        if (res.data.success === true) {
          this.$root.$emit('loading', true);
          return this.$store.dispatch('user/auth', res.data);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev Roskoshin, 2018-07-23
@anjilnew

function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {
    // Both requests are now complete
  }));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question