[Vuejs]-Axios request for one component on the server side

0👍

You have two ways to do it in Nuxt.
You can user the asyncData method:

<template>
  <div>

  </div>
</template>

<script>
export default {
  props: {
    ...
  },
  async asyncData (context) {
    // here you have access to app, store, axios if you use it, etc
    return yourData // your data will be available as a data
  }

  ...
}
</script>

You also have the possibility to use middleware. It works the same way that the asyncData method and you can also use it in a page component, but you can use it in a global way so it can be executed at every page change (useful to redirect the user under certain conditions for example)

More infos: https://nuxtjs.org/api/pages-middleware/

Leave a comment