Answer the question
In order to leave comments, you need to log in
How to pass an array to Vuex store and read this array in another component?
Help guys, I've already broken my whole head. Please give an example for this task:
There is a Menu.vue component and a Card.vue component,
In the Menu.vue component there is a table in which there are rows, by clicking on a row, the data of this row is transferred to the local array selected, for example. How can I get the value of this array on the Card.vue component and subtract it? Everyone says to use the Vuex store (but I've been trying to do it for the 3rd day and nothing is transmitted). Please give an example with an array and a store, how to properly organize a store and transfer an array.
Answer the question
In order to leave comments, you need to log in
Look, there is a method for writing data to an array:
onSelect (items) {
this.selected = items
this.$emit('selected',selected)
}
fetchData () {
this.menuVisible = !this.menuVisible;
axios.get('https://db-http.firebaseio.com/devices.json')
.then(res => {
console.log(res)
const data = res.data
const devices = []
for (let key in data) {
const device = data[key]
device.id = key
devices.push(device)
}
this.$on('selected',function(selected) {
this.devices = Object.entries(selected).map(([ id, n ]) => ({ ...n, id }));
})
})
.catch(error => console.log(error))
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question