vue-router:页面中有“音乐”、“电影”和“新闻”3 个类别选项卡,单击不同选项卡下的子栏目可以显示对应的内容

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <router-link to='/music'>音乐</router-link>
        <router-link to='/movie'>电影</router-link>
        <router-link to='/new'>新闻</router-link>
        <router-view></router-view>
    </div>
</body>

<template id="music">
    <ul>
        <li>
            <router-link to="/popmusic">流行音乐</router-link>
        </li>
        <li>
            <router-link to="/ethnicmusic">名族音乐</router-link>
        </li>
        <li>
            <router-link to="/classicalmusic">古典音乐</router-link>
        </li>
        <br>
        <router-view></router-view>
    </ul>
</template>
<template id="movie">
    <ul>
        <li>
            <router-link to="/lovemovie">爱情电影</router-link>
        </li>
        <li>
            <router-link to="/comedymovies">喜剧电影</router-link>
        </li>
        <li>
            <router-link to="/actionmovies">动作电影</router-link>
        </li>
        <br>
        <router-view></router-view>

    </ul>
</template>

<script>

    const Music = { template: '#music' }
    const Movie = { template: '#movie' }
    const New = { template: '<div>新闻内容</div>' }

    const Popmusic = { template: '<div>流行音乐内容</div>' }
    const Ethnicmusic = { template: '<div>名族音乐内容</div>' }
    const Classicalmusic = { template: '<div>古典音乐内容</div>' }

    const Lovemovie = { template: '<div>爱情电影内容</div>' }
    const Comedymovies = { template: '<div>喜剧电影内容</div>' }
    const Actionmovies = { template: '<div>动作电影内容</div>' }


    var router = new VueRouter({
        routes: [
            {
                path: '/music',
                name: 'music',
                component: Music,
                children: [
                    {
                        path: '/popmusic',
                        name: 'popmusic',
                        component: Popmusic,
                    },
                    {
                        path: '/ethnicmusic',
                        name: 'ethnicmusic',
                        component: Ethnicmusic,
                    },
                    {
                        path: '/classicalmusic',
                        name: 'classicalmusic',
                        component: Classicalmusic,
                    }
                ]
            },
            {
                path: '/movie',
                name: 'movie',
                component: Movie,
                children: [
                    {
                        path: '/lovemovie',
                        name: 'lovemovie',
                        component: Lovemovie,
                    },
                    {
                        path: '/comedymovies',
                        name: 'comedymovies',
                        component: Comedymovies,
                    },
                    {
                        path: '/actionmovies',
                        name: 'actionmovies',
                        component: Actionmovies,
                    }
                ]
            },
            {
                path: '/new',
                name: 'new',
                component: New,
            }
        ]
    })

    var vm = new Vue({
        el: '#app',
        router
    })

</script>

<style>
</style>

</html>

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

细水长流永不粹

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

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

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

打赏作者

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

抵扣说明:

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

余额充值