我正在使用Chartjs创建一个图表,该图表显示数据库中存在的信息,尽管显示了信息,但我一直收到以下错误:
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in created hook (Promise/async): "TypeError: Cannot read property 'position' of undefined"
found in
---> <Reports> at src/views/Reports.vue
<VMain>
<VApp>
<Navbar> at src/layout/Navbar.vue
<App> at src/App.vue
<Root>
还有这个:
TypeError: Cannot read property 'position' of undefined
at _callee$ (Reports.vue?0011:53)
at tryCatch (runtime.js?96cf:63)
at Generator.invoke [as _invoke] (runtime.js?96cf:294)
at Generator.eval [as next] (runtime.js?96cf:119)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _next (asyncToGenerator.js?1da1:25)
该错误将我指向此函数,在此函数中,我将信息传递给图表
async created() {
const {
data
} = await axios.get("http://localhost:4000/users");
var c = 0
for (var i = 0; i < 1000; i++) {
if (data[i].position in this.labels) {
continue
} else {
this.labels.push(data[i].position)
this.confirmed.push(data[i].id)
c = c + 1
if (c == 28) {
break
}
}
}
console.log(this.labels)
}
注:我的数据库包括列位置、ID和名称。
2条答案
按热度按时间kyxcudwk1#
是否确定
const { data } = ...
正确?axios.get
返回解析为{ response: { data: {}}
而不是{ data: {} }
的Promiseevrscar22#
如果使用created、fetch或any,则应将其包含在if语句中,如下所示:
我希望它也能解决你的问题。