Search code examples
vue.jsvuejs2axiosvuexnuxt.js

Getting Axios params to work in Async/Await function


What am I missing in this call? Does the async nature of asyncData affect the request's ability to load the param in? The network tab returns a 304 code, but no data is fetched from the backend.

import { mapGetters } from "vuex";

export default {
  computed: {
    ...mapGetters(["loggedInUser"])
  },
  head() {
    return {
      title: "Actors list"
    };
  },
  components: {
    EditProfile
  },
  async asyncData() {
    try {
      let actors = await $axios.$get(`/api/v1/actors/`, {
        params: {
          user: this.loggedInUser.id
        }
      });
      
      return { actors };
    } catch (e) {
      return { actors: [] };
    }
  },

Solution

  • Update:

    Just realize that asyncdata doesn't allow the use of 'this' or other variables from store since it's the first thing to be loaded.