Within my Vue.js
component, there is a v-select
element. Upon user selection in this widget, the toDo
function is triggered from the methods
block. However, when attempting to access the value of the filters
getter within this function, it consistently returns undefined
. Strangely enough, the DevTools in Vue indicate that this getter does indeed have a value. How can I correctly retrieve the value of the getter within the function?
QUERY:
While the filters
are effectively displayed on the interface when used in the template, they inexplicably return an undefined
result within the toDo
function. This peculiar behavior is what I aim to comprehend.
<div
v-for="filter in filters"
:key="filter.id">
<v-checkbox
v-for="(item, index) in filter.values"
:label="filter.description_values[index]"
:value="item"
:key="item"
v-model="filter.selected_values"
hide-details>
</v-checkbox>
<v-select
v-if="filter.widget==='single_dropdown'"
v-model="filter.selected_values"
:items="filter.filter_values"
label="Select ..."
dense
solo
@change="toDo">
</v-select>
</div>
***
computed: {
...mapGetters('store', [
'filters'
]),
},
methods: {
toDo: async (value) {
await console.log(this.filters) // result: undefined
}
}
***
Vuex Storage:
import { api } from '../../services/api'
export default {
namespaced: true,
state: {
filters: null
},
getters: {
filters: state => state.filters
},
mutations: {
setStateValue: (state, {key, value}) => {
state[key] = value
}
},
actions: {
getFilters: async (context) => {
await api.get('/api/filters').then((response) => {
context.commit('setStateValue', {
key: 'filters',
value: response.data
})
})
}
}
}