vue代码写完,控制台报cannot read property 'length' of underfined错误。以下是代码
fetchData () {
var cur_path = this.$route.path; //获取当前路由
var routers = this.$router.options.routes; // 获取路由对象
var nav_type = "";
for (var i = 0; i < routers.length; i++) {
var children = routers[i].children;
if(routers[i].children){
for (var j = 0; j < children.length; j++) {
var grand_children = children[j].children;
for (var k = 0; k < grand_children.length; k++) {
if (grand_children[k].path == cur_path) {
nav_type = routers[i].type;
break;
}
}
}
}
}
if (nav_type == "home") {
this.defaultActiveIndex = "/";
this.homeShow = true;
this.enterpriseShow = false;
} else if (nav_type == "enterprise") {
this.defaultActiveIndex = "/enterpriseManager";
this.homeShow = false;
this.enterpriseShow = true;
}
},
以下是报错信息