Answer the question
In order to leave comments, you need to log in
How to properly pass data from Vuex to Vue component?
Hello. I am using Vuex in an application. The component has a CHECKBOX on which v-bind hangs. On Watch, I follow the changes in the date that are tied to this checkbox and send it to the STATE. When moving to the next component, the data in the STATE is, of course, saved, and the date in the previous component is erased. So I want that when returning to the previous component, the data in DATES would still be there and those CHECKBOXES that were previously selected were selected. I'm trying to get data from STATE on CREATED and add it to DATE, and it works, but it gives errors. Tell me what is the problem please
<template>
<div>
<template v-for="filter in size">
<input type="checkbox"
class="filter-item__checkbox"
:name="filter"
:value="filter"
v-model="selectedSize"
id="size"
>
<label for="size">
{{filter}}
</label>
</template>
</div>
</template>
<script>
import {mapGetters} from 'vuex'
export default {
name: "AppSizeFilter",
data () {
return {
selectedSize: []
}
},
computed: {
...mapGetters([
"filtersSize"
]),
size() {
return this.filtersSize.values
},
selectedFilters() {
return this.$store.state.selected.filters
},
},
watch: {
selectedSize(size) {
this.$store.dispatch('updateSize', size);
}
},
created() {
if(this.selectedSize.length === 0) {
this.selectedSize = [...this.selectedFilters.selectedSize]
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question