Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Try this:

selectedCategoriesRoomCount['Business Casual'] = 2;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading