I have the following method in my Vue Component
JavaScript
x
6
1
loadMaintenances (query = {}) {
2
this.getContractorMaintenances(this.urlWithPage, query).then((response) => {
3
this.lastPage = response.data.meta.last_page
4
})
5
}
6
I want to pass the parameters (this.urlWithPage, query)
to my Vuex action as follows:
JavaScript
1
12
12
1
actions:{
2
async getContractorMaintenances ({ commit }, url, query) {
3
console.log(url);
4
console.log(query);
5
let response = await axios.get(url)
6
7
commit('PUSH_CONTRACTOR_MAINTENANCES', response.data.data)
8
9
return response
10
},
11
}
12
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:
JavaScript
1
6
1
mutations: {
2
PUSH_CONTRACTOR_MAINTENANCES (state, data) {
3
state.contractor_maintenances.push(data)
4
},
5
}
6
How can I get a value from the second parameter?
Advertisement
Answer
The 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:
JavaScript
1
2
1
async getContractorMaintenances ({ commit }, { url, query }) {
2