W
W
webivan12019-07-02 18:34:49
Vue.js
webivan1, 2019-07-02 18:34:49

Is it possible to make vuex store unique per component?

Hello!
There is a component that displays some logic and Vuex is used there for convenience.

@foreach ($item in $items)
    <mortgage-list
           :sum="{{ $item->sum }}"
           :min-fee="{{ $item->fee }}"
           :key="{{ $item->id }}"
     ></mortgage-list>
@endforeach

Now they want to display this component in a cycle, that is, there will be a lot of them on the page.
I implemented this, but now changing something in one component, it changes in all) I realized
that the store is intended for spa, but I do some tasks on vue, it turns out as modules and in some I use vuex, what should I do with this component now? Maybe somehow there is a way to tell vuex to extend its influence to only 1 component, or to remake everything on the local state?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2019-07-02
@webivan1

The idea is, of course, stupid.
You should change the data structure in the storage so that you can store data for several mortgage-list instances at once. Make an object, the keys will be id (the ones you use as key). Well, values ​​are objects with data for a separate instance. In the mortgage-list component itself, you need to add a calculated property, where the required object will be retrieved from the storage by id.

K
Kirill Romanov, 2019-07-02
@Djaler

Why not just move the state storage to the component itself?

A
Alexander Aksentiev, 2019-07-02
@Sanasol

Or pervert something like this https://codeburst.io/dynamic-modules-with-vuex-and...
key for everyone?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question