Uncaught (in promise) TypeError: Cannot set properties of undefined (setting ‘tableData‘)
错误:Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'tableData')即:此时 =>{} 中的 this 与 created 中 this 一致。箭头函数:作用域继承他的父级(created)但用 function 就不一致了。这里为回调函数,作用域会发生变化。原因:js作用域问题。
文章共177字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
错误:Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'tableData')
源代码:
created:function(){
axios.get("http://localhost:8088/user/findAll").then(function(response){
this.tableData = response.data
})
},
data(){
return {
tableData:[]
}
}
原因:
原因:js作用域问题
这里为回调函数,作用域会发生变化
解决:
created:function(){
axios.get("http://localhost:8088/user/findAll").then((response)=>{
this.tableData = response.data
})
},
原因:
箭头函数:作用域继承他的父级(created)
即:此时 =>{} 中的 this 与 created 中 this 一致
但用 function 就不一致了
更多推荐
已为社区贡献1条内容
所有评论(0)