axios请求的数据如何通过data渲染到页面上呢?

data(){
    return{
        abc:[]
    }
}

数据请求:

created() {
    axios
      .get("http://goods")
      .then(response => {
           this.abc = (JSON.parse(response.data));
      })
      .catch(error => {
        console.log("请刷新网络");
      });
      
  },

数据格式:
图片描述

问题:数据始终无法渲染到页面上。

阅读 8.2k
4 个回答
this.abc = response.data;

response.data 是数组啊,直接赋值就可以了

新手上路,请多包涵

(JSON.parse(response.data));外层括号什么意思,确定请求到数据了?请求到数据就直接能使用了,是不是你dom中写的不对

直接赋值就可以了

新手上路,请多包涵

this指向问题

created() {
    *let _this = this*
    axios
      .get("http://goods")
      .then(response => {
          *_this.abc = response.data;*
      })
      .catch(error => {
        console.log("请刷新网络");
      });
      
  },
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题