相信有同学和我一样拿到服务器返回的数据明明可以在请求中遍历成功,怎么到了别的方法就不行了,这里我也查了很多资料,经过反复尝试还是失败了,不过我得到了启发然后成功了.
这是csdn别的同志写的,反正我是没有成功-------------------------------------
// this.userList=JSON.parse(JSON.stringify(res.data.data.userList)) // this.deptList=JSON.parse(JSON.stringify(res.data.data.deptList))
--------------------------------------------------------------------------------------------------------------------
这是我用来存放信息的聊个数组
data() {
return {
account:'',
// 部门列表
deptList:[],
// 用户列表,[{},{}]
userList:[]
}
}
下面是我的请求以及我如何解决的
// 获取通讯录保存到cookie
getUserIds(){
this.$axios.get('platform/api/contact/export', {
headers: {
'accessToken': localStorage.getItem('accessToken'),
'orgSecret': localStorage.getItem('orgSecret'),
}
}).then(res => {
localStorage.setItem("userList",JSON.stringify(res.data.data.userList))
localStorage.setItem("deptList",JSON.stringify(res.data.data.deptList))
this.$notify({
title:"成功",
message:'获取通讯录成功',
type:"success"
})
}).catch(err => {
this.$notify({
title:'失败',
message:'获取通讯录失败',
type:"error"
})
})
},
// 测试遍历通讯录
testforeachUserList(){
this.userList=JSON.parse(localStorage.getItem("userList"))
for (let i=0;i<this.userList.length;i++){
console.log("======================循环内=======================")
console.log(this.userList[i].userId)
}
console.log("======================循环外=======================")
}
这是成功的