关于state、mutations和action
state 管理的状态值
mutations 方法集
action 对数据进行处理
如何使用
commit 用于调用mutations里面的方法
store.commit(‘方法’);调用vuex里面mutations的方法
dispatch 用于调用action
this.$store.dispatch(‘setTodos’); 调用action方法
映射 mapgetter mapaction
mapgetter
import {mapgetter} from ‘vuex’
computed:mapgetter[{
todo:‘allgeter’ /映射到属性todo上 通过getter拿值/
}]
==this.$store.getter.allgerter
相当于 this.$store.state.todo.todo /通过state拿值/
import {mapaction} from ‘vuex’
methods:mapaction[{‘setTodos’}] /映射为方法/
or
method :{
…mapaction[{‘setTodos’}],
}
==this.$store.dispatch(‘setTodos’); /调用action方法/
created:{
this.setTodos; /调用action 方法/
}