第六章vue无法显示商品类别
来源:6-3 vue展示商品分类数据

scloudyy
2018-09-05
老师好,我已经把vue的host改为本地,并进行了跨域的配置,但是前端仍然无法显示商品类型
在控制台内可以看到,/categorys/请求已经返回了数据,而且是正确的category的json数据,但是前端说item is null,不知道会是什么问题
2回答
-
我也遇到同样的问题了,修改了getCategory函数的定义后就好了,
getMenu(){//获取菜单
getCategory({
params:{}
}).then((response)=> {
console.log(response)
this.allMenuLabel = response.data
})
.catch(function (error) {
console.log(error);
});
},将上面this.allMenuLabel = response.data改为this.allMenuLabel = response.data.results
推测应该是js对json数据的解析并没有这么智能,由于django rest framework产生的json中包含了count,next,previous元素,js在解析这些元素的时候找不到'name'等键,导致解析失败。
232018-09-17 -
bobby
2018-09-07
https://git.imooc.com/Project/coding-131/src/master 你到这里下载最新的课程源码试试
012018-09-12
Python前后端分离开发Vue+Django REST framework实战
2880 学习 · 2467 问题
相似问题