700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 报错TypeError: Cannot set property ‘type‘ of undefined

报错TypeError: Cannot set property ‘type‘ of undefined

时间:2019-04-27 13:28:40

相关推荐

报错TypeError: Cannot set property ‘type‘ of undefined

TypeError: Cannot set property ‘type’ of undefined报错问题

<script>export default {data () {return {query: '',// 表格数据// username: "admin"// email: "adsfad@"// mobile: "12345678"// create_time: 148671// 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.mon['Authorization'] = AUTH_TOKENconst 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.dataif (status === 200) {// 给表格数据赋值this.userlist = users// 给total赋值this.total = total// 提示this.$message.success(msg)} else {this.$message.warning(msg)}}}}</script>

错误原因:

const {data: {status,msg},data: {users,total}} = res.data

仔细看代码,发现const里面有两个对象,两个都是data,而后台返回的数据应该是一个data和一个meta。

这里也告诉小伙伴们,敲代码的时候一定要细心

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。