K
K
Kiril Kharkevich2019-01-15 14:40:31
Vue.js
Kiril Kharkevich, 2019-01-15 14:40:31

How to correctly set an array in the Vuex store and pass values ​​​​to it, as well as subtract from it?

There is a menu component that contains devices with checkboxes. When a device is selected, its data is transferred and written to the array, but the array that is in this component. How to set an array in the Vuex store and pass data to it, and how to read information from this array on another component?
An example of how I display devices with checkboxes and read data (selected array):

<md-list>
          <md-list-item class="general"  @click="showAllDevices">
            <md-icon>settings_input_composite</md-icon>
            <span class="md-list-item-text">Всі пристрої</span>
          </md-list-item>

          <md-list-item md-expand>
            <md-icon>touch_app</md-icon>
            <span  class="md-list-item-text" >Пристрій</span>
            <md-list  slot="md-expand">
            <md-table v-model="devices" md-card @md-selected="onSelect">
  
      <md-table-row slot="md-table-row" slot-scope="{ item }" :md-disabled="item.named.includes('Stave')" md-selectable="multiple" md-auto-select>
        <md-table-cell md-label="Обрати всі пристрої">{{ item.named }}</md-table-cell>
      </md-table-row>
    </md-table>
          </md-list>
          </md-list-item>
  <tr>
        <td>{{ selected }}</td>
      </tr>
          
        </md-list>

Method that writes data to an array:
onSelect (items) {        //вибір чекбоксів пристроїв в меню
        this.selected = items
      },
      getAlternateLabel (count) {
        let plural = ''

        if (count > 1) {
          plural = 's'
        }

        return `${count} user${plural} selected`
      }
      }

Help implement this with Vuex Store

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shmatuan, 2019-01-15
@shmatuan

Here is an example of how crud works right away, but it’s better to read the official docks (in Russian)
https://codeburst.io/build-a-simple-todo-app-with-...

V
Vladimir Malkov, 2019-01-15
@MalkovVladimir73

Welcome to the Russian-language documentation on vuex . We read all the basic concepts . It will take 15 minutes, but everything will fall into place by itself. (+ in the examples from the docks, your problems are almost solved).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question