其他分享
首页 > 其他分享> > Vue3项目运行时报错误:TypeError:router.addRouters is not a function

Vue3项目运行时报错误:TypeError:router.addRouters is not a function

作者:互联网

router.addRouters()方法报错:Uncaught (in promise) TypeError: router.default.addRouters is not a function。

 

原因分析:

新版VueRouter废除了addRoutes();//添加的数组

改为addRoute(RouteRecordRaw);//添加的为对象

 

解决办法:

原代码为:

const routers = store.getters.addRouters;
router.addRoutes(routers);

修改为:

const routers = store.getters.addRouters;
routers.forEach((route) => {
  router.addRoute(route);
});

即可解决。

标签:function,TypeError,const,routers,Vue3,addRoute,router,addRouters
来源: https://www.cnblogs.com/rainbow70626/p/16457790.html