Hello,
This is the problem I submitted last week at dhtmlx.com/blog/use-dhtmlxgantt … work-demo/.
Requesting data to the $axios.post interface when calling vue When you use gantt.parse() to render data later, you will get an error.
The specific example is as follows.
gantt.init(this.$refs.gantt);
gantt.parse(this.$props.tasks);
let params = new URLSearchParams();
params.append('orderId', this.$route.params.orderId);
this.$axios.post('/api/proPlan/groupPlanTree', params, {emulateJSON: true})
.then((res) => {
if (res.data.status === true) {
let data = res.data.model;
// let taskData = {};
let links = [];
for (const i in data) {
let linksData = {
id: data[i].id,
source: data[i].id,
target: data[i].parent,
type: '0',
lag: 0
};
links.push(linksData);
}
let taskData = {
data: data,
links: links
};
this.tasks = taskData;
this.$nextTick(function () {
gantt.parse(taskData);
})
}
})
Reporting error under Chrome:
vue.esm.js?efeb:591 [Vue warn]: Error in mounted hook: “TypeError: Cannot read property ‘length’ of undefined”
found in
—> at src\components\gantt\gantt.vue
at src\components\gantt\ganttHome.vue
at node_modules\element-ui\packages\container\src\main.vue… (1 recursive calls)
at src\components\index\index.vue
at src\App.vue
TypeError: Cannot read property ‘length’ of undefined
at o._parseInner (dhtmlxgantt.js?1c57:11)
at o.parse (dhtmlxgantt.js?1c57:11)
at n.t._process_loading (dhtmlxgantt.js?1c57:11)
at n.t.on_load (dhtmlxgantt.js?1c57:11)
at n.t.parse (dhtmlxgantt.js?1c57:11)
at VueComponent.mounted (gantt.vue?17f0:215)
at callHook (vue.esm.js?efeb:2921)
at Object.insert (vue.esm.js?efeb:4158)
at invokeInsertHook (vue.esm.js?efeb:5960)
at VueComponent.patch [as patch] (vue.esm.js?efeb:6179)