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 badges
Add a ment  | 

1 Answer 1

Reset to default 10

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:

async getContractorMaintenances ({ mit }, { url, query }) {

本文标签: javascriptPassing multiple parameters to Vuex actionStack Overflow