Vue uses the tree component under the iview component library to report an error when loading data asynchronously.

problem description

vue uses the tree component under the iview component library to report an error when loading data asynchronously

the environmental background of the problems and what methods you have tried

according to the official document, child nodes can be loaded asynchronously using the load-data attribute, and loading needs to be added to the data to identify whether it is currently being loaded.
the first parameter of load-data is the current node information; the second parameter of load-data is executed, passing in the data that needs to be added.
if a node does not contain loading and children fields, the asynchronous load effect is not applied.
Portal:
https://www.iviewui.com/compo.

related codes

/ / Please paste the code text below (do not replace the code with pictures)
html
< Tree: data= "classList": load-data= "loadClassData" class= "mytree" ref= "tree" > < / Tree >

js
axios request
if (res.result_code = = 1) {

res.classList.forEach(i => {
    //havaNextClasstrue
    if (i.havaNextClass) {
        i.loading = false;
        i.children = [];
    }
});

this.classList = res.classList;

Asynchronous loadClassData method:
also after a successful axios request:
if (res.result_code = = 1) {

res.classList.forEach(i => {
    if (i.havaNextClass) {
        i.loading = false;
        i.children = [];
    }

});
callback (res.classList);

what result do you expect? What is the error message actually seen?

when you click on a normal node whose havaNextClass is true, that is, when it is not a leaf node, the data loads normally and the tree control is normal, but when you click on the leaf node (there is no next level at the end), the page is normal, but the console reports an error:
Uncaught TypeError: Cannot read property "length" of undefined

at VueComponent.handleExpand (iview.js?0536:25872)
at invoker (vue.esm.js?efeb:2027)
at HTMLSpanElement.fn._withTask.fn._withTask (vue.esm.js?efeb:1826)

add judgment to the asynchronous method and, try catch also reports this error. I probably know that reporting this error means that there are no child nodes under the node, that is, the array in front of length no longer exists or I copy and modify the official sample code for undefined, (change it to a leaf node and a non-leaf node, also report an error). I don"t know if this is an official bug.?. Although the page does not affect, but it looks very uncomfortable, a slight code cleanliness fetish. Please give me some advice


callback (res.classList);
you should have passed undefined

here.
tree.loadData(item, children => {
    ...
    if (children.length) {// undefined null
        ...
    }
});
Menu