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

后端 未结 11 818
予麋鹿
予麋鹿 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:49

    I got the same problem still stuck ...

    Wrote these according to Evan(Vue Author) JSON.parse(JSON.stringify(res.data)) method, But why can't normal data?

      methods: {
        async getdata() {
          console.log(1);
          await axios.get(API).then((res) => {
              console.log(2);
              if (!this.dataList.length) {
                this.dataList = JSON.parse(JSON.stringify(res.data));
                console.log(3);
                console.log(res.data, 'res.data ');
                console.log(this.dataList, 'this.dataList')
                console.log('----------check-----------',JSON.parse(JSON.stringify(res.data)));
              }
            })
            .catch(err => {
              console.error('failed: ' + err);
            })
          console.log(4);
        },
    

提交回复
热议问题