在actions里用axios的话,直接引入就好了import 'axios'
获取state里的数据也可以直接引state,不过一般都是接收外面传过来的参数
改变state值当然是通过mutations改变了,通过actions里的context.commit嗲用mutations里的方法(可以把参数传过去),在mutations里改state
actions:
import axios form 'axios'
const actions = {
setMutation (context, params) {
axios.get(params.url, {params: params})
.then(res => {
context.commit('setInfo', res.info)
})
}
}
export default actions
mutations:
const mutations = {
setInfo (state, params) {
state.info = params.info
}
}
export default mutations