E
E
Ernest Faizullin2020-05-24 19:54:11
Vue.js
Ernest Faizullin, 2020-05-24 19:54:11

Vuex reusable modules. Best practice?

Hi all.

I'll try to explain briefly (if you need to clarify anything)

1. We have a list of objects (let's say questions)
2. Each question is rendered in the question component
3. I want to make a Store for each question
4. How I try:
In the question component in the mounted method (or created?) I register the module like this

this.namespace = 'question-' + this.question.id
this.store. 
registerModule(this.namespace, questionStore)


Am I doing the right thing? If yes, then I have another clarification, questions can have answers, answers can have actions, and so on. Should I also keep nesting by namespace (e.g. `question-${this.question.id}/answers/answer/${this.currentAnswer.id}`)?

I want in this topic, in detail and once and for all, to decide how normal enlightened people do

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2020-05-24
@bootd

Why do you need a separate repository for each question? Here you need 1 storage questions with an array of questions, then just create a loop in the template and display all the questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question