I'm 99% sure that you can't. There are a couple ways around this depending on what you're doing.
If you have an array of items and you use one item at a time and you need to get/store the current/active item.
const state = {
items: [],
current: null
}
const mutations = {
[SET_CURRENT](state, item) {
state.item = item
},
[SET_CURRENT_BY_ID](state, id) {
state.current = state.items.find((item) => item.id == id)
}
}
const getters = {
items: (state) => state.items,
currentItem: (state) => state.current,
}
If you want to get an item on the fly based on a dynamic attribute, you have to use a computed property:
computed: {
current() {
return this.$store.getters.items.find((item) => item.id == this.current)
}
},
data() {
return {
current: 0
}
}