Getters
jsx
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {
num: 10,
},
getters: {
doubleNum(state) {
return state.num * 2;
},
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vue
<template>
<div>
<p>{{ $store.getters.doubleNum }}</p>
<p>{{ doubleNum }}</p>
</div>
</template>
<script>
export default {
data() {
return {};
},
computed: {
doubleNum(){
return this.$store.getters.doubleNum
}
},
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19