fe-interview icon indicating copy to clipboard operation
fe-interview copied to clipboard

[vue] 怎样动态加载路由?

Open haizhilin2013 opened this issue 7 years ago • 5 comments

[vue] 怎样动态加载路由?

haizhilin2013 avatar Jun 20 '19 20:06 haizhilin2013

router.addRoutes

Sihan-Tan avatar Jul 24 '19 03:07 Sihan-Tan

image

zlqGitHub avatar Dec 23 '19 10:12 zlqGitHub

<div id="first">
    <router-link to="/a">老八一号</router-link>
    <router-link to="/b">老八二号</router-link>
    <router-link to="/c">老八三号</router-link>
    <router-link to="/d">老八四号</router-link>
    <router-view></router-view>
</div>
<script>
    let a={
        template:`<h1>奥里给 干了 兄弟们</h1>`
    };
    let b={
        template:`<h2>虽然不是同一个时间,但是是同一个撤所儿</h2>`
    };
    let c={
        template:`<h3>就吃老八秘制晓汉堡儿</h3>`
    };
    let d={
        template:`<h2>老八秘制晓汉堡  既便宜它还管饱</h2>`
    };

    let routerObj=new VueRouter({
        routes:[
            {path:'/a',component:a,name:'一号'},
            {path:'/b',component:b,name:'二号'}
        ]
    });
    routerObj.addRoutes([
        {path:'/c',component:c,name:'三号'},
        {path:'/d',component:d,name:'四号'}
    ]);
    let vm=new Vue({
        el:"#first",
        data:{},
        router:routerObj
    })
</script>

vue-router的addRoutes方法

lancelote-zpc avatar Mar 19 '20 03:03 lancelote-zpc

router.addRoutes

WenJieLi1998 avatar Apr 19 '20 01:04 WenJieLi1998

动态添加路由:router.addRoute; 动态加载路由->懒加载?

const Foo = () => import('./Foo.vue')

Drikold avatar Jul 26 '21 00:07 Drikold