【发布时间】:2021-09-03 19:45:37
【问题描述】:
我正在使用 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 和名称。
【问题讨论】:
标签: javascript vue.js axios chart.js