我的 Vue 组件中有以下方法
loadMaintenances (query = {}) {
this.getContractorMaintenances(this.urlWithPage, query).then((response) => {
this.lastPage = response.data.meta.last_page
})
}
我想将参数 (this.urlWithPage, query)
传递给我的 Vuex 操作,如下所示:
actions:{
async getContractorMaintenances ({ commit }, url, query) {
console.log(url);
console.log(query);
let response = await axios.get(url)
commit('PUSH_CONTRACTOR_MAINTENANCES', response.data.data)
return response
},
}
问题是第一个参数 url
返回一个值,而第二个参数 query
返回 undefined
。
我的突变如下:
mutations: {
PUSH_CONTRACTOR_MAINTENANCES (state, data) {
state.contractor_maintenances.push(...data)
},
}
如何从第二个参数中获取值?
答案 0 :(得分:3)
对 this 的公认答案也适用于 actions
,它需要两个参数:context
和 payload
。
为了传递多个值,您必须将数据作为对象发送并对其进行解构:
async getContractorMaintenances ({ commit }, { url, query }) {