Vuex Getter Hook with parameters
P粉530519234
P粉530519234 2023-08-29 18:45:19
0
1
560
<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>
P粉530519234
P粉530519234

reply all(1)
P粉518799557

Add another computed property named projectById that accepts route parameters as arguments and returns the project:

computed: {
    ...mapGetters(["currentUserPhoto","getProjectById"]),
   projectById(){
         return this.getProjectById(this.$route.params.id)
  }

},
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!