How do I leave my objects in static JS?

Asked

Viewed 51 times

-2

I’ll explain what’s going on,

well when I create an application with vuejs or React, I use fetch to retrieve information from the api and then pass the data within a state (in the case of vuejs I use return { info: [] })

When I call this object I put to display inside the HTML, then the information appears but when I give F5 they give refresh...

Does anyone know any solution to take the refresh when refreshing the page?

  • Want to avoid calling the correct API again? Your application has a server?

  • I’m working locally, I’m not using server yet.

  • And it doesn’t just happen with API, I’ve also used firebase and the same thing happens

1 answer

0

You can persist the data in Storage, when starting the application you load the saved data. This is for browser memory, type a cookie. If you want to persist definitive you must save the changes in the API to rescue them when loading the application. A small example of storage in Storage:

// Gravar
localStorage.setItem("lastname", "Smith");
// Recuperar
variavel = localStorage.getItem("lastname");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.