Vue JS returns [__ob__: Observer] data instead of my array of objects

后端 未结 11 844
予麋鹿
予麋鹿 2020-12-08 08:54

I\'ve created a page where I want to get all my data from the database with an API call, but I\'m kinda new to VueJS and Javascript aswell and I don\'t know where I\'m getti

11条回答
  •  臣服心动
    2020-12-08 09:45

    As mentioned by Husam Ibrahim, you should wait the async fetch() function to resolve. Another approach could be use async/await in your function:

    methods: {
        async fetchPigeons(){
            await fetch('api/racingloft')
                   .then(res => res.json())
                   .then(res => {
                       console.log(res.data);
                       this.pigeons = res.data;
                   })
        }
    }
    

    And then it should work:

    
    

提交回复
热议问题