This doesn't seem to align with the intended purpose of a vuex getter.
From the examples provided, it is clear that getters are typically used as computed properties.
<script>
import { mapGetters } from "vuex"
export default {
computed: {
...mapGetters(['someGetter'])
},
mounted() {
console.log(this.someGetter); // Keep in mind that a computed property is not a method.
}
}
</script>
If you require the getter to accept arguments, it might be more appropriate to use a method instead of a computed property.
Consider utilizing a store action like this:
new Vuex.Store({
actions: {
someMethod({ state }, arg){
// Perform operations using state.someValue and the argument
return transformedState;
}
}
})
Actions and mutations can be mapped as methods, allowing for usage like the following:
<script>
import { mapActions } from "vuex"
export default {
computed: {
},
mounted() {
// Invoke someMethod with arguments in your component
this.someMethod('the argument');
},
methods: {
...mapActions(['someMethod'])
},
}
</script>
The first parameter of an action is the store itself, providing access to the state. This applies to dispatch and commit functions as well.
Please note that an action can only receive one parameter (payload). If multiple parameters need to be passed, they must be wrapped in an object or array.
this.someMethod({ arg1, arg2, ...});