0

I've a little problem with my vuejs global function. I created this global function in my app.js

export function getSession(key) {
  $.post('/api/session', function (result) {
    if (result.hasOwnProperty(key)) {
        return result[key];
    }
  });
}

If i echo the return of this function in a vue component at the mounted() part the console tells me undefined. But if i replace line 4 with console.log(result[key]) I get the right value.

Why is this so. Please help!

Markus
  • 407
  • 2
  • 9
  • 25
  • 3
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Ayush Gupta Mar 10 '18 at 12:27
  • Show more info. Show the code that is using this function, how it is importing it. Any answer is context dependant. – acdcjunior Mar 10 '18 at 13:13

0 Answers0