question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Help needed] Using promise in vue-resource

See original GitHub issue

Hi, Thanks for your help and reading this:

I am trying to make two api calls and then combine the results together.

Here is my current approach using Promise.all, In the feature, it says ’ Support Promise API’ , what does it mean? Could you kindly show an example how to do it with Vue-resource. Thanks vey much!

var promise1 = new Promise((resolve, reject) => {
    Vue.http.get('url1').then((response) => {
      resolve(response.json())
    }, (response) => {
      reject(response.status)
    })
  })
  var promise2 = new Promise((resolve, reject) => {
    Vue.http.get('url2').then((response) => {
      resolve(response.json())
    }, (response) => {
      reject(response.status)
    })
  })
  Promise.all([promise1, promise2]).then(([v1,v2]) => {
    // Process of merging results v1 and v2 together here
  })

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

16reactions
hfalucascommented, Jul 7, 2016

@mikeyao

var promise1 = Vue.http.get('url1'); // note there is no then or catch callbacks
var promise2 = Vue.http.get('url2');

Promise.all([promise1, promise2]).then(([v1,v2]) => {
    // Process of merging results v1 and v2 together here
  })
0reactions
a-kriyacommented, Aug 16, 2017

For anyone looking for an answer to the above question: yes, vue-resource takes care of Promise.all (and other Promise methods as well).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue Resource and promises - Laracasts
Hi,. I can use some help getting my promises to work with Vue Router and Vue Resource. ... My first example can work...
Read more >
Intercept Promise error with vue-resource - Stack Overflow
I'm using vue-resource and my interceptor is the following: Vue.http.interceptors.push(function(request, next) { ...
Read more >
VueJS - Why you should be using promises - YouTube
If you want the source code let me know in the comments section and I will upload it as soon as possible. Please...
Read more >
Reacting to Promises from event listeners in Vue.js - Medium
First things first, returning the promise. Its a good practice to always return promises from functions, that way you can await them, if...
Read more >
Vue-resource json() is promise? - Get Help
How can I retrieve my data from my response object in vue-resource 1.0.x? this.$http.get('/api').then(function(response){ response.json() ?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found