解决VUE的Object出现的undefined问题

  • Post author:
  • Post category:vue


this.axios
            .get('http://xxx/xxx/xxxxx')
            .then(res => {
              this.cxsp = res[0];
              console.log(this.cxsp)

在这里插入图片描述

调用时显示undefined

  console.log(this.cxsp.shangp_id)

在这里插入图片描述

用错了是因为传来的值是一个list,list里有2个list,原以为this.cxsp就能一次打开。但其实要打开2次。第一次拆开外面list,到2个list的一层,再this.cxsp[0]获取里面第一个list的键和值,具体解决方法:

 console.log(this.cxsp[0].shangp_id)
 //或者
 console.log(res[0][0].shangp_id)

在这里插入图片描述



版权声明:本文为qq_31493411原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。