How to Pass a Two-Dimensional Array to Vue3

Asked 1 years ago, Updated 1 years ago, 308 views

I am creating a test app with Vue3 in Google Apps Script.

I've tried many things with client-side Javascript, but I can't turn it around with v-for, whether the two-dimensional array is Object type?How should I hand it over?
If you return a solid array, it will work, so please advise me that there is no problem with setting up a CDN.

javascript.html

<script>
function initializeVue(values){

const app = {
  data(){
    US>return{
      lists —values
    }
  }
}

Vue.createApp(app).mount('#app')

}

google.script.run.withSuccessHandler(initializeVue).getSpreadsheetValues();

</script>

code.gs

function getSpreadsheetValues()
{
  return SpreadsheetApp.getActiveSpreadsheet().getDataRange().getValues();
}

javascript google-apps-script vuejs

2022-12-06 08:24

1 Answers

I've tried many things with client-side Javascript, but I can't turn it around with v-for?, SplreadsheetApp.getActiveSpreadsheet().getDataRange().getValues() because of situations like returning solid arrays.In this case, the values returned by withSuccessHandler is null.This seems to be a specification for now.Ref

So, how about the following changes?For this change, change getSpreadsheetValues() as follows:getDisplayValues() returns the cell value as a string.

return SpreadsheetApp.getActiveSpreadsheet().getDataRange().getValues();
return SpreadsheetApp.getActiveSpreadsheet().getDataRange().getDisplayValues();

Note:

  • If you want to use the Date object of the value obtained from the spreadsheet as a Date object on the Javascript side, you may need to change it to a string or Unix time on the Google Apps Script side and then return it to the Date object on the Javascript side.


2022-12-06 08:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.