Vuex Operations
# Vuex Operations
import { mapActions, mapMutations, mapGetters } from 'vuex'
computed: {
...mapGetters([ // Get data, parameter is an array
'searchHistory' // Equivalent to adding searchHistory and its data to data
])
},
methods: {
someMethod(){
this.saveSearchHistory(passedValue)
},
...mapActions([ // Dispatch actions to modify data, parameter is an array because the actions file has already encapsulated the methods
'saveSearchHistory' // Equivalent to binding saveSearchHistory as a method
]),
someMethod() {
this.setFullScreen(passedValue)
},
...mapMutations({ // Commit mutations, parameter is an object
setFullScreen: 'SET_FULL_SCREEN' // Equivalent to binding setFullScreen as a method
})
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Edit (opens new window)
Last Updated: 2026/03/21, 12:14:36