V6 - async data()

I am migrating from V5 to V6.

In all my components, i used to have

{

async data() {
const user = await fetch(‘some/path’).then(res => res.json());
return {
user,
};
},

}

What is the best method to integrate my data loading when going in a component ?

I am a little bit lost

Using async/await https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await

export default async () => {
  let users = await fetch(‘some/path’).then(res => res.json());
  return $render;
}
1 Like