vue路由

本文详细介绍了一个使用Vue.js和Vue Router实现的多页面应用案例,包括页面间的导航、嵌套路由及动态组件加载。通过具体代码展示了如何组织和管理复杂的前端路由结构。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
<router-link to="/first">第一页</router-link>
<router-link to="/second">第二页</router-link>
<router-link to="/third">第三页</router-link>
<router-view></router-view>
</div>
<template id="fir">
    <div>
        <h1>第一页</h1>
        <router-link to="/first/aaa">FUZE</router-link>
        <router-link to="/first/bbb">ASH</router-link>
        <router-view></router-view>
    </div>
</template>

<template id="sec">
    <h1>第二页</h1>
</template>

<template id="thi">
    <h1>第三页</h1>
</template>

<template id="aa">
    <h2>人质</h2>
</template>

<template id="bb">
    <h2>RUSH B</h2>
</template>

<script>
    let Aaa=Vue.component("aaa",{
        template:"#aa"
    });
    let Bbb=Vue.component("bbb",{
        template:"#bb"
    });
    let Fir=Vue.component("first",{
        template:"#fir"
    });
    let Sec=Vue.component("second",{
        template:"#sec"
    });
    let Thi=Vue.component("third",{
        template:"#thi"
    });
    let router=new VueRouter({
        routes:[
            {path:"/",redirect:"/first"},
            {path:"/first",component:Fir,
                children:[
                    {path:"/first/aaa",component:Aaa},
                    {path:"/first/bbb",component:Bbb}
                ]},
            {path:"/second",component:Sec},
            {path:"/third",component:Thi},
        ]
    });
    new Vue({
        el:"#app",
        redirect:"/ftist",
        router,


    });

</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值