Skip to content
Advertisement

Vue JS – Helper Async Await function to fetch data returning undefined

In vuejs I’m using a helper file with some custom functions that I ll use everywhere in the project.

I was refactoring some async await promises, but I cant seem to solve it.

I wish to call the fetchUserData(123), for example, and get the data back to the method. Although the request is made and have valid results, the userData const is undefined.

What I’m doing wrong ?

component.vue : this one prints out, Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘then’)

JavaScript

component.vue : this one prints out, undefined

JavaScript

util.js

JavaScript

Advertisement

Answer

you got a few errors in your code here are the solutions:

component.vue

JavaScript

util.js

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement