Vuex Getter Hook with parameters
P粉530519234
2023-08-29 18:45:19
<p>I defined a vuex getter function with parameters, the code is as follows: </p>
<pre class="brush:php;toolbar:false;">const getters = {
getProjectById: (state) => (id) => {
return state.projects.find(project => project.id === id)
}
}</pre>
<p>Now, I want to use this getter function in my component, but I can't find a way to pass parameters to the getter. </p>
<p>This is my getter hook computed property: </p>
<pre class="brush:php;toolbar:false;">computed: {
...mapGetters(["currentUserPhoto","getProjectById"])
},</pre>
<p>Is it possible to pass the Id parameter from the route to the "getProjectId" getter? If possible, what is the best approach? </p>
Add another computed property named
projectById
that accepts route parameters as arguments and returns the project: