No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Data Table failed for prop "data". Expected Array, got Object.

    Help
    3
    5
    5977
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jwdobken last edited by

      I just started with Vue and have to following issue.

      My data is object oriented, such as:

      {
      22: {name:"John", id:22, friends:[5,31,55], works:{books:[], films:[],}
      12: {name:"Ivan", id:12, friends:[2,44,12], works:{books:[], films:[],}
      }
      

      retreived with the following state attribute:

      computed: {
        ...mapState({
          persones: state => state.persons.persons
        }),
      

      So I get an expected warning:

      [Vue warn]: Invalid prop: type check failed for prop “data”. Expected Array, got Object.

      Now, to solve the issue I would use lodash’ toArray:

      computed: {
        ...mapState({
          persones: state => _.toArray(state.persons.persons)
        }),
      

      But now, the persons attributes is empty ALWAYS

      1 Reply Last reply Reply Quote 0
      • M
        Max last edited by Max

        looking at your data structure, you dont have an array of objects! you have one object!
        you should supply an array of objects from your backend, this will solve your problem:

        [
        {name:"John", id:22, friends:[5,31,55], works:{books:[], films:[]},
        {name:"Ivan", id:12, friends:[2,44,12], works:{books:[], films:[]}
        ]
        
        1 Reply Last reply Reply Quote 0
        • benoitranque
          benoitranque last edited by

          Use this

          computed: {
            ...mapState({
              persones: state => Object.values(state.persons.persons)
            }),
          
          1 Reply Last reply Reply Quote 0
          • J
            jwdobken last edited by jwdobken

            Ah… the answer by @benoitranque did solve my issue, but now the table is not updated dynamically :s when I add a new person (on the same page) I have to refresh to see it

            1 Reply Last reply Reply Quote 0
            • benoitranque
              benoitranque last edited by

              @jwdobken I’m not surprised. Using a function in the mapState helper is new to me. You should use getters instead. Your code would look like this:

              // store.js
              export default new Vuex.Store({
                state: {
                  persons: {
                    persons: {
                      // this is the data you want
                    }
                  }
                },
                getters: {
                  allPersons (state) {
                    return Object.values(state.persons.persons)
                  }
                }
              })
              // if using the new structure in quasar 0.15, in getters.js
              export function allPersons (state) {
                return Object.values(state.persons.persons)
              }
              
              // usage in a .vue component
              import { mapGetters } from 'vuex'
              export default {
                computed: {
                  // if using root store
                  ...mapGetters({
                    persons: 'allPersons'
                  }),
                  // if using store module
                  ...mapGetters('storeModuleName', {
                    persons: 'allPersons'
                  }),
                }
              }
              
              1 Reply Last reply Reply Quote 1
              • First post
                Last post