J
J
jekanok2019-02-07 17:29:07
Vue.js
jekanok, 2019-02-07 17:29:07

How to pass value to dispatch vuex?

Here is the code

import { Store } from "vuex";

export default {
  async asyncData({ store, params }) {
    await store.dispatch("getPosts");
    await store.dispatch("getComment",1); // как передать значение которое находится в postId? если через this.postId не работает 

    return {
      post: store.getters.posts,
      comments: store.getters.comments
    };
  },
  created: function() {
    var postId = this.$route.params.id;
    this.post = this.post[postId - 1];
    console.log(params);
  }
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Mosin, 2019-02-07
@jekanok

async asyncData({ store, params }) {
    await store.dispatch("getPosts");
    await store.dispatch("getComment", params.id); 

    return {
      post: store.getters.posts,
      comments: store.getters.comments
    };
  },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question