TypeError: Cannot set property 'type' of undefined error reporting problem
<script>
export default {
data () {
return {
query: '',
// 表格数据
// username: "admin"
// email: "[email protected]"
// mobile: "12345678"
// create_time: 1486720211
// mg_state: true
// id: 500
// role_name: "主管"
userlist: [],
total: -1,
pagenum: 1,
pagesize: 2
}
},
created () {
this.getList()
},
methods: {
async getList () {
// query查询参数可以为空
// pagenum当前页码不能为空
// pagesize每页显示条数不能为空
// 需要授权的 API ,必须在请求头中使用 Authorization 字段提供 token 令牌
const AUTH_TOKEN = localStorage.getItem('token')
this.$http.defaults.headers.common['Authorization'] = AUTH_TOKEN
const res = await this.$http.get(`users?query=${
this.query}&pagenum=${
this.pagenum}&pagesize=${
this.pagesize}`)
console.log(res)
const {
data: {
status,
msg
},
data: {
users,
total
}
} = res.data
if (status === 200) {
// 给表格数据赋值
this.userlist = users
// 给total赋值
this.total = total
// 提示
this.$message.success(msg)
} else {
this.$message.warning(msg)
}
}
}
}
</script>
wrong reason:
const {
data: {
status,
msg
},
data: {
users,
total
}
} = res.data
Looking at the code carefully, I found that there are two objects in the const, both of which are data, and the data returned by the background should be a data and a meta.
I also tell my friends here that you must be careful when typing the code