Z
Z
Zhalgas Saparov2019-12-25 07:55:17
JavaScript
Zhalgas Saparov, 2019-12-25 07:55:17

How to pull parameters from asyncData nuxt?

How can I get parameters from asyncData in mounted()?
I need to rewrite the page because on reboot, it crashes due to the fact that it is trying to pull out data that is not there yet. This page was written by a proger before me, and in order to fix it, I decided to rewrite it, but I need to get this params, how can I do this?
Here is the code:

async asyncData({ store, params, redirect }) {
    await store.dispatch("getPlaycategories");
    await store.dispatch("getPlayground", params.id);
    let data = JSON.parse(JSON.stringify(store.state.playground));
    let param = params
    this.params = param // this.params, я создал в data() и пытаюсь присвоить ей значение из param
    if (store.state.user.id != data.owner) {
      redirect("/mycabinet");
    }

    let playcategory = store.state.playcategories.find(
      item => item.id == data.category
    );
    let booking_data = await store.dispatch("getPlaygroundBooking", params.id);
    let months = ru.months;

    return {
      data,

      modalShow: false,
      testIndex: "0",

      booking_data,
      playcategory,
      filter: {
        date: {
          from: null,
          to: null
        },
        search: "",
        type: null,
        sort: -1
      },
      months
    };
  },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2019-12-25
@IgorPI

Colleague, set the default data.in data

data: function () {
      return {
        organization: {
          name: "",
          reviews: [],
          images: [],
        }
    },

async asyncData({query, $axios}) {

      let params = Object.assign({}, query)

      let organization = {}
      await $axios.$get(`${process.env.api}/organizations.getById`, {
        params
      }).then(({code, data}) => {
        organization = data
      });


      return {
        organization
      }
    },

After these manipulations, there will be nothing to crumble.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question