我使用VUE通过接口读取json存入mylist1中,但读取count和werkstatt时报错undefined。
请帮写一句代码吧,谢谢!
data(){
return{
mylist1: [],
}
}
"methods":{
lookup(){
this.axios({ ...
}).then((response) => {
console.log('1. index.vue--lookup数据传入开始!')
this.mylist1 = response.data.list1
console.log('response.data.list1: ', this.mylist1)
console.log('response.data.list1[\'count\']: ', this.mylist1.count)
console.log('response.data.list1[\'werkstatt\']: ', this.mylist1.werkstatt)
}
}
}
你打印下this.mylist1是什么数据类型,如果是字符串,用JSON.parse转一下
通过接口查询数据,看你axios请求,接口也没有的么;你返回的response打印看一下json格式
以下是我的案例
this.$axios({
url: '/apiIP/sys-user/userLogin',
method: 'post',
data: params,
})
.then(res => {
if(res.data.code != '2000') return this.$message.error({message:res.data.message,showClose:true,duration:1000});
// localStorage.setItem("token",res.data.result.token)
localStorage.setItem("userMsg",JSON.stringify(res.data.result))
//
this.$router.push('/Customer/Admin');
})