请使用 Vue 路由相关知识动手实现 Tab 栏切换案例,要求如下。① 创建一个 components/Message.vue 组件,用来展示页面内容。② 创建 3 个子路由,分别是“待付款” “

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>使用路由实现Tab栏切换</title>

    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>

    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

    <style>

        *{

            margin: 0;

            padding: 0;

        }

        #app{

            width:100%;

        }

        #app ul{

            height: 30px;

            list-style: none;

            display: flex;

            flex-wrap: wrap;

            align-content: flex-center;

            align-items: center;

            justify-content: space-around;

            text-align: center;

           

        }

        #app>ul>li{

            border: 1px solid red;

            flex: 1;

        }

        li a{

            width: 100%;

            text-decoration: none;

            line-height: 30px;

            display: inline-block;

        }

        .pay p{

            text-align:center;

            line-height: 200px;

        }

        /*  */

      .router-link-active{

        background-color: #09f;

        color: #fff;

      }

    </style>

</head>

<body>

    <div id="app">

        <ul>

            <li>

                <router-link to="/payment">待付款</router-link>

            </li>

            <li>

                <router-link to="/deliver">待发货</router-link>

            </li>

            <li>

                <router-link to="/receive">待收货</router-link>

            </li>

        </ul>

        <!-- 路由匹配到的组件将渲染在这里 -->

        <router-view></router-view>

    </div>

    <template id="Payment">

        <div class="pay">

            <p>待付款商品信息</p>

        </div>

    </template>

     

    <template id="Deliver">

        <div class="pay">

            <p>待发货商品信息</p>

        </div>

    </template>

    <template id="Receive">

        <div class="pay">

            <p>待收货商品信息</p>

        </div>

    </template>

<script>

    // 1 定义路由组件

    const ListOne = {template:'#Payment'}

    const ListTwo = {template:'#Deliver'}

    const ListThree = {template:'#Receive'}

    // 2 定义路由,创建 router 实例

    const router=new VueRouter({

        routes:[

            { path: '/', redirect: '/payment' },

            { path:'/payment',component:ListOne },

            { path:'/deliver',component:ListTwo },

            { path:'/receive',component:ListThree }

        ]

    });

    // 3 创建和挂载根实例

    const app = new Vue({

        router

    }).$mount('#app')

</script>

</body>

</html>

运行结果:

 

 

 

  • 14
    点赞
  • 96
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Werfgf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值