Home > Blockchain >  How can I change the key name in the data when making a post request
How can I change the key name in the data when making a post request

Time:01-20

I have the following problem:

I want to send my form data to a rest api and the form in my data looks like this:

data(){
    return {
        form: {
              ...
              selectedCategoriesRoomCount: {
                 categoryName: '',
                 roomCount: ''
              }
        }
  }
}
    

when I make a post request with axios the json data looks like this:

selectedCategoriesRoomCount {
    categoryName: "Business Casual",
    roomCount: "2"
}

But I need the key value pair to look like this:

selectedCategoriesRoomCount: {
    "Business Casual": "2"
},

How can I achieve that? Thank you in advance

CodePudding user response:

Try this:

selectedCategoriesRoomCount['Business Casual'] = 2;
  •  Tags:  
  • Related