入门Vuex
State
获取State中的值的三种方法
- 直接在模板里面写
1 | <p>{{ $store.state.count }}</p> |
- 通过计算属性
1 | computed: { |
- 通过mapstate
1 | computed: mapState(['count']) |
Mutations
- 直接写在模板里面(不传值)
1 | <button @click="$store.commit('add')">+</button> |
- 通过mapmutations(推荐,传值不传值都可以使用)
1 | const mutations = { |
1 | methods: { |
1 | <button @click="add()">+</button> |
getters
- 一般写法
1 | const getters = { |
1 | computed: { |
- 简写
1 | const getters = { |
1 | computed: { |
actions
1 | methods: { |
1 | <button @click="addAction">+</button> |
1 | const actions = { |