C
C
Carbon8952019-08-19 11:19:39
Vue.js
Carbon895, 2019-08-19 11:19:39

How to pull Store Vuex into modules?

Hello everyone, I'm learning Vue, there was a problem with dividing the Store into modules for each component, I found the Vuex documentation , but it didn't help with everything, because VS code emphasizes state and payload, if you hover it writes an implicit type.
What to do?
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hyuugo, 2019-08-20
@Hyuugo

You can create a module directory, separate state, actions, mutations, getters into separate files in it and import them into the main store.
Module example.
store file.

E
egerr, 2019-08-20
@egerr

At one time, I wrote guard hooks for the admin panel and found an excellent article, where there was a good example of organizing a state to the heap. I use this approach in my project, it is very convenient.
The storage is also convenient in that you can place part of the logic there and receive data in the components already with processing. For example, let's say we received the post data from the server, after that we do something with it in the mutation, for example, we run it with a regular expression, and then we save it in state.post.
article in Russian
original article
project files on github
if in a nutshell. create a repository (state directory), after which we import it into main.js - profit.
in components, we get data from the storage using getters.
For example

<script>
  export default {
    name: 'Post',

     created() {
      this.$store.dispatch(POST_REQUEST, this.$route.params.id);
    },

    computed: {
      ...mapGetters(['post',]),
    },
  };
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question