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: '
新闻内容
'
} const Popmusic = { template: '
流行音乐内容
'
} const Ethnicmusic = { template: '
名族音乐内容
'
} const Classicalmusic = { template: '
古典音乐内容
'
} const Lovemovie = { template: '
爱情电影内容
'
} const Comedymovies = { template: '
喜剧电影内容
'
} const Actionmovies = { template: '
动作电影内容
'
} 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>

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

你可能感兴趣的:(vue.js)