admin管理员组文章数量:1278881
I have the following method in my Vue Component
loadMaintenances (query = {}) {
this.getContractorMaintenances(this.urlWithPage, query).then((response) => {
this.lastPage = response.data.meta.last_page
})
}
I want to pass the parameters (this.urlWithPage, query)
to my Vuex action as follows:
actions:{
async getContractorMaintenances ({ mit }, url, query) {
console.log(url);
console.log(query);
let response = await axios.get(url)
mit('PUSH_CONTRACTOR_MAINTENANCES', response.data.data)
return response
},
}
The problem is that the first parameter url
is returning a value but the second one query
is returning undefined
.
My mutation is as follows:
mutations: {
PUSH_CONTRACTOR_MAINTENANCES (state, data) {
state.contractor_maintenances.push(...data)
},
}
How can I get a value from the second parameter?
I have the following method in my Vue Component
loadMaintenances (query = {}) {
this.getContractorMaintenances(this.urlWithPage, query).then((response) => {
this.lastPage = response.data.meta.last_page
})
}
I want to pass the parameters (this.urlWithPage, query)
to my Vuex action as follows:
actions:{
async getContractorMaintenances ({ mit }, url, query) {
console.log(url);
console.log(query);
let response = await axios.get(url)
mit('PUSH_CONTRACTOR_MAINTENANCES', response.data.data)
return response
},
}
The problem is that the first parameter url
is returning a value but the second one query
is returning undefined
.
My mutation is as follows:
mutations: {
PUSH_CONTRACTOR_MAINTENANCES (state, data) {
state.contractor_maintenances.push(...data)
},
}
How can I get a value from the second parameter?
Share Improve this question edited Jan 19, 2021 at 11:57 Dan Knights 8,3784 gold badges27 silver badges54 bronze badges asked Jan 18, 2021 at 22:02 user3714932user3714932 1,3532 gold badges18 silver badges31 bronze badges1 Answer
Reset to default 10The accepted answer to this also applies to actions
, it expects two arguments: context
and payload
.
In order to pass multiple values you'll have to send the data across as an object and destructure them:
async getContractorMaintenances ({ mit }, { url, query }) {
本文标签: javascriptPassing multiple parameters to Vuex actionStack Overflow
版权声明:本文标题:javascript - Passing multiple parameters to Vuex action - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741266102a2368493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论