[Vuejs]-How to pass array object parameter from vue website to google appscript to set google spreadsheet column value

0๐Ÿ‘

โœ…

By checking the output of JSON.stringify(e), it seems that each property of objects become different parameters and are received as something like the following:

{
  "queryString": "settingLink=settingLinkTest&albumLink=albumLinkTest&stepControl=stepControlTest&nav%5B0%5D%5Bstyle%5D=red&nav%5B0%5D%5Bcontent%5D=test&nav%5B1%5D%5Bstyle%5D=blue&nav%5B1%5D%5Bcontent%5D=test&nav%5B2%5D%5Bstyle%5D=green&nav%5B2%5D%5Bcontent%5D=test",
  "contextPath": "",
  "parameters": {
    "nav[1][style]": [
      "blue"
    ],
    "nav[1][content]": [
      "test"
    ],
    "albumLink": [
      "albumLinkTest"
    ],
    "nav[2][style]": [
      "green"
    ],
    "settingLink": [
      "settingLinkTest"
    ],
    "nav[2][content]": [
      "test"
    ],
    "nav[0][style]": [
      "red"
    ],
    "stepControl": [
      "stepControlTest"
    ],
    "nav[0][content]": [
      "test"
    ]
  },
  "contentLength": -1,
  "parameter": {
    "nav[2][content]": "test",
    "nav[1][content]": "test",
    "albumLink": "albumLinkTest",
    "settingLink": "settingLinkTest",
    "nav[0][style]": "red",
    "stepControl": "stepControlTest",
    "nav[0][content]": "test",
    "nav[1][style]": "blue",
    "nav[2][style]": "green"
  }
}

Since the index of a particular nav and its properties become names of parameters, you can get their values by changing your doGet() to:

SheetName.getRange("F2").setValue(params["nav[0][style]"]);
SheetName.getRange("G2").setValue(params["nav[1][style]"]);
SheetName.getRange("H2").setValue(params["nav[2][style]"]);

Alternatively, as suggested in the comments of the question, you can stringify the nav object when sending it:

this.$http.get(appurl, {
          params: {
            settingLink: settingLink,
            albumLink: albumLink,
            stepControl: stepControl,
            nav: JSON.stringify(nav)
          }
        }).then(response => {
          console.log(response);
        })

And then parsing when you receive it to use as you intended:

var nav = JSON.parse(params.nav);
SheetName.getRange("F2").setValue(nav[0].style);
SheetName.getRange("G2").setValue(nav[1].style);
SheetName.getRange("H2").setValue(nav[2].style);

Leave a comment