[SOLVED] App.request.get result to page data - vuejs


#1

Hey Guys,

Have an issue here - I understand why it’s occurring, just not what to do to mitigate it.

I am using a dynamic route to pass an ID of an object in my database and on loading the page, I have an app.request.get to get the full details of the object through my API.

The issue is, of course, the app.request.get is asynchronous so the page is loaded and by the time this api call is successfully the page is already initialized.

What is the correct method to pass the result of my app.request.get call to the pages data function so I can display and use it as normal?

One method I saw to use is on my route add an async to my path and pass the result of the api call to the resolve callbacks’s context, only issue with this is I couldn’t work out how to get the context on the page to display.

Any help would be appreciated.

Cheers


#2

Solved it.
In my success callback, it seems by setting my data object differently fixed it

const self = this;

and then referencing my data object with

self.myDataOby = …

Works

In my code, I was using this instead which didn’t work.

this.myDataOby = …

hey if it works it works lol


#3

Or maybe you can use => function