效果

实现

Vue Router 官方文档

https://router.vuejs.org/zh/guide/

用 Vue.js + Vue Router 创建单页应用,是非常简单的。使用 Vue.js ,我们已经可以通过组合组件来组成应用程序,当你要把 Vue Router 添加进来,我们需要做的是,将组件 (components) 映射到路由 (routes),然后告诉 Vue Router 在哪里渲染它们。

新建Vue项目

参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/84481606

项目地址:

https://github.com/badaoliumang/vuemusicplayer

删改组件

删掉HelloWorld.vue,在src下新建pages目录,用于存放单页面。

下载静态资源assert,将src下的assets替换掉。

静态资源下载地址:

CSDN:

https://download.csdn.net/download/badao_liumang_qizhi/10806811

Github:

https://github.com/badaoliumang/VueMusicPlayerAssert

修改Vue项目

App.vue

删掉div中的img,将style中的代码修改为

*{margin:0;padding:0;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-text-size-adjust:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;font-family:Arial, "微软雅黑";}
img{border:none;max-width:100%;vertical-align:middle;}
body,p,form,input,button,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6{margin:0;padding:0;list-style:none;overflow-x:hidden}
h1,h2,h3,h4,h5,h6{font-size:100%;}
input,textarea{-webkit-user-select:text;-ms-user-select:text;user-select:text;-webkit-appearance:none;font-size:1em;line-height:1.5em;}
table{border-collapse:collapse;}
input,select,textarea{outline:none;border:none;background:none;}
a{outline:0;cursor:pointer;*star:expression(this.onbanner=this.blur());}
a:link,a:active{text-decoration:none;}
a:visited{text-decoration:none;}
a:hover{color:#f00;text-decoration:none;}
a{text-decoration:none;-webkit-touch-callout:none;}
em,i{font-style:normal;}
li,ol{list-style:none;}
html{font-size:16px;}
.clear{clear:both;height:0;font-size:0;line-height:0;visibility:hidden; overflow:hidden;}
.fl{float:left;}
.fr{float:right;}
body{ margin:0 auto;max-width:640px; min-width:320px;color:#555;background:#f1f1f1;height:100%;}
a{color: #222;text-decoration: none}
.router-link-active{color: red !important;}

修改后的App.vue完整代码

<template><div id="app"><!-- 路由出口 --><!-- 路由匹配到的组件将渲染在这里 --><router-view/></div>
</template><script>
export default {name: 'App'
}
</script><style>
*{margin:0;padding:0;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-text-size-adjust:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;font-family:Arial, "微软雅黑";}
img{border:none;max-width:100%;vertical-align:middle;}
body,p,form,input,button,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6{margin:0;padding:0;list-style:none;overflow-x:hidden}
h1,h2,h3,h4,h5,h6{font-size:100%;}
input,textarea{-webkit-user-select:text;-ms-user-select:text;user-select:text;-webkit-appearance:none;font-size:1em;line-height:1.5em;}
table{border-collapse:collapse;}
input,select,textarea{outline:none;border:none;background:none;}
a{outline:0;cursor:pointer;*star:expression(this.onbanner=this.blur());}
a:link,a:active{text-decoration:none;}
a:visited{text-decoration:none;}
a:hover{color:#f00;text-decoration:none;}
a{text-decoration:none;-webkit-touch-callout:none;}
em,i{font-style:normal;}
li,ol{list-style:none;}
html{font-size:16px;}
.clear{clear:both;height:0;font-size:0;line-height:0;visibility:hidden; overflow:hidden;}
.fl{float:left;}
.fr{float:right;}
body{ margin:0 auto;max-width:640px; min-width:320px;color:#555;background:#f1f1f1;height:100%;}
a{color: #222;text-decoration: none}
.router-link-active{color: red !important;}
</style>

新建主页面index.vue

在pages文件夹下新建文件index.vue

用于主页面。

<template lang="html">
<div class="index"><ul><li><router-link to="/home"><img src="../assets/logo-ea5.png" alt=""></router-link></li><li><router-link to="/artists">歌手</router-link></li><li><router-link to="/listcate">榜单</router-link></li><li><router-link to="/ucenter">我的</router-link></li><li><router-link to="/search">搜索</router-link></li></ul><router-view />
</div>
</template><script>
export default {
}
</script><style scoped>.index img{width: 26px;height: 26px;
}.index ul{display: flex;height: 50px;line-height: 50px;background: #f9f9f9;
}.index ul li {flex: 1;text-align: center;
}.index ul li a{font-size: 16px;color: #999;
}</style>

新建歌手页面artists.vue

<template lang="html"><div class="">歌手页面</div>
</template><script>
export default {
}
</script><style lang="css">
</style>

新建home.vue主页面

<template lang="html"><div class="">主页面</div>
</template><script>
export default {
}
</script><style lang="css">
</style>

新建listcate榜单页面

<template lang="html"><div class="">榜单</div>
</template><script>
export default {
}
</script><style lang="css">
</style>

新建search.vue搜索页面

<template lang="html"><div class="">搜索</div>
</template><script>
export default {
}
</script><style lang="css">
</style>

新建ucenter.vue我的页面

<template lang="html"><div class="">我的</div>
</template><script>
export default {
}
</script><style lang="css">
</style>

Router下的index.js修改

import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/pages/index'
import Home from "@/pages/home"
import Artists from "@/pages/artists"
import ListCate from "@/pages/listcate"
import Ucenter from "@/pages/ucenter"
import Search from "@/pages/search"
Vue.use(Router)export default new Router({routes: [{path: '/',name: 'Index',component: Index,children:[{path: 'home',component: Home},{path:"artists",component:Artists},{path:"listcate",component:ListCate},{path:"ucenter",component:Ucenter},{path:"search",component:Search}]}]
})

项目总结构

项目是在Atom中打开,关于Atom的使用等参考:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/83280765

总结说明

1.在index.vue中

<!-- 使用 router-link 组件来导航. -->
<!-- 通过传入 `to` 属性指定链接. -->
<!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->

2.在index.vue中

<!-- 路由出口 -->
 <!-- 路由匹配到的组件将渲染在这里 -->
 <router-view></router-view>

3.定义路由组件

可以从其他文件import进来

在router下的index.js中

import Index from '@/pages/index'
import Home from "@/pages/home"
import Artists from "@/pages/artists"
import ListCate from "@/pages/listcate"
import Ucenter from "@/pages/ucenter"
import Search from "@/pages/search"

4.定义路由

在在router下的index.js中

// 每个路由应该映射一个组件。 其中"component" 可以是
// 通过 Vue.extend() 创建的组件构造器,
// 或者,只是一个组件配置对象。

  {path: '/',name: 'Index',component: Index,children:[{path: 'home',component: Home},

还可以表示嵌套关系,加children。

启动项目

在项目目录下打开cmd命令行输入:

npm start

然后打开浏览器窗口,输入:

http://localhost:8080/#/

然后打开检查选项,谷歌浏览器按F12键,将浏览器模拟为手机

此部分代码对应分阶段代码中阶段一

分阶段代码下载位置:

https://download.csdn.net/download/badao_liumang_qizhi/10846557

Vue实现仿音乐播放器4-Vue-router实现音乐导航菜单切换相关推荐

  1. html音乐播放器代码自动,html5 css3音乐播放器代码

    特效描述:html5 css3 音乐播放器代码.html5 css3音乐播放器代码 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 标题歌手 00:00/00:00 var music ...

  2. 如何在php中添加音乐播放器,window_Win10自带Groove音乐播放器怎么使用?,《Groove音乐》是微软在Win10系 - phpStudy...

    Win10自带Groove音乐播放器怎么使用? <Groove音乐>是微软在Win10系统上推出的一款最新的音乐播放器,从而替代了之前的Xbox Music.而今天<Groove音乐 ...

  3. python实现在线音乐播放器(懒皮鼠音乐)

    python实现在线音乐播放器(懒皮鼠音乐) 利用qt设计requests库实现在线音乐播放 文章目录 python实现在线音乐播放器(懒皮鼠音乐) 前言 一.qt设计师设计界面 二.使用步骤 1.引 ...

  4. Android音乐播放器eclipse,简单的Android音乐播放器 eclipse开发的基于Android平台的音乐播放器 - 下载 - 搜珍网...

    压缩包 : 音乐播放器.zip 列表 音乐播放器/ 音乐播放器/.classpath 音乐播放器/.project 音乐播放器/.settings/ 音乐播放器/.settings/org.eclip ...

  5. VueDemo3:音乐播放器[黑马Vue基础网课跟写](vue,axios)

    VueDemo3:音乐播放器 一.歌曲搜索 1.按下回车(v-on,enter) 2.查询数据(axios 接口 v-model) 3.渲染数据(v-for 数组 that) 服务器返回的数据比较复杂 ...

  6. android 音乐播放器 获取sd卡所有音乐文件,Android Studio音乐播放器无法读取SD卡,只有内部存储器...

    我很抱歉,如果这原来是一个愚蠢的问题,它可能会成为一个快速修复,但我只是无法弄清楚.我在android studio中创建了音乐播放器,并且没有任何sdcard上的歌曲不会显示在列表视图中,只有内部内 ...

  7. linux 中文 音乐播放器,linux下的常见音乐播放器

    xmms 老牌的音乐播放器,模仿Windows下*的播放器Winamp,其强大的功能不输于Winamp,具有极强的可扩展性,支持mp3.ogg.wav等格式播放,添加插件后还可以播放AAC.wma等格 ...

  8. android音乐播放器案例,Android MediaPlayer实现音乐播放器实例代码

    Android MediaPlayer实现音乐播放器 1.布局文件 android:layout_width="fill_parent" android:layout_height ...

  9. 开源音乐播放器_如何选择开源音乐播放器

    开源音乐播放器 Linux提供了大量的音乐播放器. 您如何选择使用哪一个? 早在2016年6月,我就写了我最喜欢的开源音乐播放器Guayadeque显然逝世的文章. 我描述了我对Guayadeque真 ...

  10. python制作音乐播放器_python实现音乐播放器 python实现花框音乐盒子

    本文实例为大家分享了python实现音乐播放器的具体代码,供大家参考,具体内容如下 """这是一个用海龟画图模块和pygame的混音模块制作的简易播放器. 作者:李兴球, ...

最新文章

  1. R语言使用timeROC包计算存在竞争情况下的生存资料多个标记物在相同时间下的cox及协变量分析AUC值、并可视化多个标记物在相同时间下的ROC值、多指标的ROC曲线(Time-dependent R
  2. POJ 1577 Falling Leaves (子母二叉树,给出叶子节点的删除序列,求前序遍历)
  3. C# 模拟鼠标移动与点击
  4. An ffmpeg and SDL Tutorial
  5. 线性代数【一】:行列式的概念与计算
  6. java接收前端参数
  7. 语音合成 g2p 字典设计
  8. 剑桥禁书与一个自由的灵魂
  9. 基于STM32F103单片机的智能婴儿床智能风扇系统
  10. 数据链路层-点对点通信方式
  11. django-mysql 中的金钱计算事务处理
  12. 到底多大并发才算高并发?一文带你全面认识高并发!
  13. 每年的风能部署必须增长四倍,才能到2050年实现净零排放
  14. js实现省市区三级联动
  15. TJA1050国产替代DP1050T高速 CAN 总线收发器
  16. Chrome Network面板工具之万文多图详解
  17. 新一代态势感知系统发布——北望
  18. 小米怎么快速回到顶部_[玩机教程:App推荐篇 01] | 小米视频 极速版(MiVideo-Lite)...
  19. 计算两坐标点球面距离、两向量夹角及多边形面积
  20. 文思海辉与雅观科技达成战略合作,加速智慧场景应用落地

热门文章

  1. paradox 修改字段长度_【精华】小学作文400字汇总十篇
  2. J.U.C系列(五)BlockingQueue的使用
  3. spring cloud全家桶_阿里架构师玩转spring全家桶(实战篇),附赠3本spring电子书...
  4. java map赋值_java 中的map怎么没有办法赋值?
  5. mvc @html.textboxfor 添加正则表示式,如何在C#/ MVC 4中的Html.TextBoxFor中输入占位符文本...
  6. html css js实现快递单打印_JS与HTML、CSS实现2048小游戏(六)
  7. linux源代码调用,linux – 哪里可以找到系统调用源代码?
  8. 日产ftt传感器是什么_日产将发布最牛自动驾驶:选最棒的陪驾,走最快的车道...
  9. python opencv 录制视频_Python利用opencv实现录制视频
  10. 外部接口需求怎么写_软件需求规约怎么写