Display JSON array in Vuejs

dkgcb picture dkgcb · Nov 25, 2018 · Viewed 8.8k times · Source

I'm getting this data from the Coldfusion Framework/1 API in JSON format:

{
  "COLUMNS": [
    "PRODUCT_ID",
    "PRODUCT_NAME",
    "PRODUCT_STATUS",
    "DT_CREATED"
  ],
  "DATA": [
    [
      102,
      "Window",
      "In Production",
      "November, 02 2018 10:33:13"
    ],
    [
      105,
      "Window",
      "Delivered",
      "November, 11 2018 15:00:00"
    ],
    ETC...
  ]
}

In developer tools, using Vue tool, I got this:

  • data
    • errored: false
    • loading: true
    • windows: Object
      • COLUMNS: Array[4]
      • DATA: Array[22]

I'm using axios

new Vue({
    el: '#windows-list-data',
    data() {
      return {
      windows: null,
      loading: true,
      errored: false
    }
 },
mounted() {
  axios
    .get('https://my-server.local/index.cfm?action=api.get')
    .then( response => {
      this.windows = response.data

     })
    .catch( error =>  {
      console.log(error) 
      this.errored = true
    })
    .finally( () => this.loading = false )
}

Can someone tell me how to render the data in Vuejs in a view? thanks

Answer

crifan picture crifan · Feb 25, 2020

seems should change

this.windows = response.data

to

let respDataStr = response.data
let jsObject = JSON.parse(respDataStr)
this.windows = jsObject