继上一篇开发音乐播放器歌单列表页

1.使用router定义跳转链接,2. 使用axios得到音乐第三方数据,并渲染到页面上,3.组件之间传值(props)

1.接下来使用了vue-router路由动态传值,父子嵌套式路由 

this.$router.push({
path: `/recommend/${item.id}`
});

2.router入口文件定义路由路径:

3. 此时需要渲染路由在父组件中:

B.使用vuex进行状态管理:

npm install vuex --save
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

定义一个state,getters,mutations,方便组件中使用:

export 导出vuex定义模块

第二栏效果图:

主要代码:

<template>
<div >
<div class="wrapper" ref='wrapper'>
<div class="content">
<listview
title="推荐歌单"
:showPlayCount="true"
:showSinger="false"
:limit="6"
:resources="recommendList"
@select="selectedList"></listview>
<listview
title="最In音乐"
:showPlayCount="false"
:showSinger="true"
:limit="6"
:resources="newList"
@select="selectedList"></listview>
<listview
title="主播电台"
:showPayCount="false"
:showSinger="true"
:limit="6"
:resources="djrecommend"
@select="selectedList"></listview>
</div>
<router-view></router-view>
</div> </div>
</template>
<script>
import Listview from '@/components/listview/listview'
import {mapGetters, mapMutations} from 'vuex'
import store from "@/store/store.js";
export default{
name:"recommend",
store,
data(){
return {
list:null
} },
components:{
Listview, },
methods: {
//定义selectedList方法,router.push路由跳转
selectedList(item) {
this.$router.push({
path: `/recommend/${item.id}`
});
console.log(item);
this.setSongList(item);
},
...mapMutations([
'setSongList'
]) },
created(){
/*this.axios
.get('http://localhost:3000/top/playlist/highquality')
.then((response)=>{
this.list = response.data.playlists // console.log(this.list)
})
.catch((response)=>{
console.log(response)
})*/
this.recommendList = 'http://localhost:3000/top/playlist/highquality';
this.newList='http://localhost:3000/top/playlist?order=hot';
this.djrecommend='http://localhost:3000/personalized/djprogram';
} }
</script>
<style lang="scss" rel="style/scss"> </style>

歌单列表页

<template>
<transition name="fade">
<music-list :songs="songs" :id="id">
</music-list>
</transition>
</template> <script>
import {mapGetters} from 'vuex';
import musicList from '@/components/music-list/music-list' export default {
name: "list-detail",
data() {
return {
songs: {},
id: ''
}
},
created() {
this._getSongList();
},
methods: {
_getSongList() {
if (!this.songList || !this.songList.id) {
this.$router.push('/recommend');
return;
}
//使用vuex定义的数据得到父组件的相关值
this.songs = this.songList;
this.id = this.songList.id;
},
},
computed: {
...mapGetters([
'songList'
])
},
components: {
musicList
}, }
</script> <style lang="scss">
.fade-enter-active, .fade-leave-active {
transition: all 0.3s;
} .fade-enter, .fade-leave-to {
opacity: 0;
} </style>

子组件传值给歌曲列表页

<template>
<div class="music-list">
<div class="header">
<div class="header-img">
<img :src="songs.coverImgUrl">
<div class="play-count"><i class="icon iconfont icon-headset"></i>{{songs.playCount|unitConvert}}</div>
<div class="detail-btn"><i class="icon iconfont icon-detail"></i></div>
</div>
<div class="header-content">
<div class="name">{{songs.name}}</div>
<div class="tags" v-show="songs.tags">
<span>标签: </span><span class="tag" v-for="(tag,idx1) in songs.tags" :key="idx1">{{tag}}</span>
</div>
<div class="subname" v-if="songs.subscribers && songs.subscribers.length > 0">
{{songs.subscribers[0].nickname}}<span class="create-time">创建于{{songs.createTime}}</span>
</div>
</div>
<div class="back" @click="back">
<i class="icon iconfont icon-close"></i>
</div>
<div class="background">
<img :src="songs.coverImgUrl">
</div>
</div>
<div class="body">
<div class="header-bar">
<i class="icon iconfont icon-play"></i><span class="playAll">播放全部<i
class="count">(共{{detail.length}}首)</i></span>
<span class="collect"><i class="icon iconfont icon-add"></i>收藏({{subscribedCount|unitConvert}})</span>
</div>
<div class="songList-wrapper" ref="listWrapper">
<ul class="songlist">
<li class="song-item" v-for="(item, idx) in detail" :key="idx" @click="selectItem(item, idx, $event)">
<div class="line-number">
<span>{{idx+1}}</span>
</div>
<div class="item-content">
<div class="songname">{{item.name}}</div>
<div class="songer">{{item.ar[0].name}} - {{item.al.name}}</div>
</div>
<div class="tool">
<i class="icon iconfont icon-tool"></i>
</div>
</li>
</ul> </div> </div> </div>
</template> <script> import {unitConvert} from '@/common/js/unitConvert'
import {mapGetters, mapActions} from 'vuex' export default {
name: "music-list",
//得到list-detail传过来的id,并获取第三方数据,渲染到页面中
props: {
songs: {
type: Object
},
id: {
type: [String, Number]
}
},
data() {
return {
detail: [],
subscribedCount: ''
}
},
created() {
if (this.id) {
let url = `http://localhost:3000/playlist/detail?id=${this.id}`;
this.axios.get(url).then((res) => {
this.detail = res.data.playlist.tracks;
this.subscribedCount = res.data.playlist.subscribedCount; })
} },
methods: {
back(){ },
...mapActions([
'selectPlay'
])
},
filters: {
unitConvert(num) {
return unitConvert(num);
}
}
}
</script> <style lang="scss">
@function px2rem($px) {
@return $px / 30 + rem;
}
.music-list {
position: fixed;
z-index: 200;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #fff;
.header {
position: relative;
display: flex;
width: 100%;
height: px2rem(400);
align-items: center;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.2);
.header-img {
display: flex;
position: relative;
justify-content: center;
flex: 0 0 px2rem(300);
width: px2rem(300);
height: px2rem(250);
img {
width: px2rem(250);
height: px2rem(250);
}
.play-count {
position: absolute;
top: 0;
right: px2rem(40);
color: #fff;
font-size: px2rem(24);
font-weight: bold;
.icon-headset {
color: #fff;
font-size: px2rem(24);
font-weight: bold;
margin-right: px2rem(8);
}
}
.detail-btn {
position: absolute;
bottom: 0;
right: px2rem(42);
color: #fff;
.icon-detail {
font-size: px2rem(36);
font-weight: bold; }
}
}
.header-content {
flex: 1;
height: px2rem(250);
padding-right: px2rem(25);
color: #fff;
.name {
margin: px2rem(20) 0;
height: px2rem(90);
font-size: px2rem(32);
font-weight: bold;
}
.tags {
margin-bottom: px2rem(24);
font-size: px2rem(26);
line-height: px2rem(26);
height: px2rem(26);
.tag {
padding: 0 px2rem(12);
border: 2px solid #fff;
border-radius: px2rem(8);
margin-left: px2rem(12);
}
}
.subname {
font-size: px2rem(26);
line-height: px2rem(26);
height: px2rem(26);
.create-time {
margin-left: px2rem(10);
} } }
.icon-close {
position: absolute;
top: 0;
right: px2rem(16);
padding: px2rem(20);
color: #fff;
font-size: px2rem(32);
font-weight: bold;
}
.background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: px2rem(400);
z-index: -1;
filter: blur(px2rem(100));
overflow: hidden; }
}
.body {
.header-bar {
display: flex;
line-height: px2rem(80);
height: px2rem(80);
border-bottom: 1px solid #eee;
justify-content: center;
text-align: center;
.icon-play {
width: px2rem(80);
font-size: px2rem(48);
}
.playAll {
flex: 1;
font-size: px2rem(26);
text-align: left;
.count {
font-size: px2rem(24);
font-style: normal;
color: #7e8c8d;
}
}
.collect {
padding: 0 px2rem(24);
background: #F93021;
color: #fff;
font-size: px2rem(26);
font-weight: bold;
text-align: center;
.icon-add {
font-size: px2rem(26);
color: #fff;
font-weight: bold;
}
}
}
.songList-wrapper {
position: absolute;
top: px2rem(480);
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
.songlist {
background: #fff;
.song-item {
display: flex;
&.list-complete-enter-active, &.list-complete-leave-active {
transition: all 0.2s linear;
}
&.list-complete-enter, &.list-complete-leave-to {
opacity: 0;
transform: translateY(px2rem(30));
}
.line-number {
flex: 0 0 px2rem(80);
width: px2rem(80);
height: px2rem(80);
line-height: px2rem(80);
text-align: center;
font-size: px2rem(30);
color: #7e8c8d; }
.item-content {
flex: 1;
border-bottom: 1px solid #eee;
width: 80%;
.songname {
font-size: px2rem(28);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; }
.songer {
font-size: px2rem(22);
color: #7e8c8d;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; } }
.tool {
flex: 0 0 px2rem(80);
width: px2rem(80);
line-height: px2rem(80);
border-bottom: 1px solid #eee;
text-align: center;
.icon-tool {
font-size: px2rem(30); }
} }
}
} }
} </style>

歌曲列表页

router的相关定义:

import Vue from 'vue'
import Router from 'vue-router'
import Helloworld from '@/components/HelloWorld'
import Recommend from '@/page/recommend'
import HotRecommend from '@/page/hotrecommend'
import Search from '@/page/search'
//引入子组件
import recommendList from '@/page/list-detail' Vue.use(Router) export default new Router({
routes: [
{
path: '/',
component: Helloworld
},
{
path: '/recommend',
component: Recommend,
//子组件路由
children: [
{
path: ':id',
component: recommendList
}
]
},
{
path: '/Hotrecommend',
component: HotRecommend
},
{
path: '/search',
component: Search
}
]
})

嵌套式路由实用

vuex-- store.js设定:

import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
const state = {
// count:1,
songList:null
}
const getters = {
songList:function(state) {
return state.songList;
}
}
const mutations = {
/*increment(state){
state.count++
},
decrement(state){
state.count--
},*/
setSongList(state,item) {
state.songList=item;
}
}
const actions={
/*increment: ({commit})=>{
commit('increment')
},
decrement: ({commit})=>{
commit('decrement')
},*/
/* selectPlay: ({commit, state}, {list, index})=>{
commit('setPlayList',list)
},
*/
} export default new Vuex.Store({
state,
mutations,
getters,
actions
})

state,mutations,getters定义

vueJs开发音乐播放器第二篇(点击歌单跳出详情页)的更多相关文章

  1. Linux终端音乐播放器cmus攻略: 操作歌单

    目录 1. 安装 2. 操作说明 2.1. *PlayList歌单 2.2. 其他 3. 视图切换 4. 使响应Media/play按键 4.1. 编译安装 cmus是一款开源的终端音乐播放器.它小巧 ...

  2. android开发音乐播放器--Genres和Art album的获取

    最近在做一个项目,其中涉及到音乐播放器.当用到Genres和Art album时花费了一些时间才搞定,今天把方法草草列出,以供自己以后忘记时查看,也希望可以帮助碰到同样问题的道友!! 一.Genres ...

  3. python音乐播放器第二版

      此代码是上一期的改版 需要用到的Python库有 .pygame 2.time 3.xmusic(我自己写的用来做音乐索引) .colorama(美观) 推荐使用pip安装 方法: pip ins ...

  4. 用Vue来实现音乐播放器(九):歌单数据接口分析

    z这里如果我们和之前获取轮播图的数据一样来获取表单的数据  发现根本获取不到 原因是qq音乐在请求头里面加了authority和refer等 但是如果我们通过jsonp实现跨域来请求数据的话  是根本 ...

  5. iOS开发拓展篇—音频处理(音乐播放器3)

    iOS开发拓展篇—音频处理(音乐播放器3) 说明:这篇文章主要介绍音频工具类和播放工具类的封装. 一.控制器间数据传递 1.两个控制器之间数据的传递 第一种方法:self.parentViewCont ...

  6. iOS开发拓展篇—音频处理(音乐播放器1)

    iOS开发拓展篇—音频处理(音乐播放器1) 说明:该系列文章通过实现一个简单的音乐播放器来介绍音频处理的相关知识点,需要重点注意很多细节的处理. 一.调整项目的结构,导入必要的素材 调整后的项目结构如 ...

  7. iOS开发拓展篇—音频处理(音乐播放器2)

    iOS开发拓展篇—音频处理(音乐播放器2) 说明:该文主要介绍音乐播放界面的搭建. 一.跳转 1.跳转到音乐播放界面的方法选择 (1)使用模态跳转(又分为手动的和自动的) (2)使用xib并设置跳转 ...

  8. iOS开发拓展篇—音频处理(音乐播放器4)

    iOS开发拓展篇—音频处理(音乐播放器4) 说明:该文主要介绍音乐播放器实现过程中的一些细节控制. 实现的效果: 一.完整的代码 YYPlayingViewController.m文件 // // Y ...

  9. iOS开发拓展篇—音频处理(音乐播放器5)

    iOS开发拓展篇—音频处理(音乐播放器5) 实现效果: 一.半透明滑块的设置 /** *拖动滑块 */ - (IBAction)panSlider:(UIPanGestureRecognizer *) ...

  10. iOS开发拓展篇—音频处理(音乐播放器6)

    iOS开发拓展篇—音频处理(音乐播放器6) 一.图片处理 说明: Aspect表示按照原来的宽高比进行缩放. Aspectfit表示按照原来的宽高比缩放,要求看到全部图片,后果是不能完全覆盖窗口,会留 ...

随机推荐

  1. Python---time对象的使用获取时间

    https://www.jb51.net/article/49326.htm 1.time.time() 它返回当前时间的时间戳(1970纪元后经过的浮点秒数). 如果调用这个函数,如:  print ...

  2. Jetty的ssl模块

    启用ssl模块,执行如下命令: java -jar $JETTY_HOME/start.jar --add-modules=ssl 命令的输出,如下: INFO : ssl initialized i ...

  3. 深入了解 Spring Cloud Config、Spring Cloud Gateway 与断路器模式

    Spring Microservices 是一个框架,它使用 Spring 框架更容易地构建和管理基于微服务的应用程序.微服务是一种架构风格,其中一个大型应用程序被构建为一组小型.独立可部署的服务.每 ...

  4. Python 数组和列表:创建、访问、添加和删除数组元素

    Python 没有内置支持数组,但可以使用 Python 列表来代替. 数组 本页将向您展示如何使用列表作为数组,但要在 Python 中使用数组,您需要导入一个库,比如 NumPy 库.数组用于在一 ...

  5. Seaborn分布数据可视化---统计分布图

    统计分布图 barplot() sns.barplot( x=None, y=None, hue=None, data=None, order=None, hue_order=None, estima ...

  6. 上新啦KIT

    HMS Core上新啦!分析服务区服分析全新上线:机器学习服务OCR新增手写识别服务:3D建模续扫能力更新:视频编辑服务支持自定义上传素材--更多#HMS Core#能力可点击网页链接了解. 了解更多 ...

  7. Qt使用https协议发送带参数的post请求

    背景: 现在公司项目需要做一个检测更新的功能,通过访问后台接口,判断是否需要更新. 后台接口是 https 协议的,接口需要post请求,需要带参数,来判断是哪个软件需要做检测更新的操作. 客户端软件 ...

  8. 【编译原理】Antlr 入门使用

    前面文章我们学习了编译器前端的词法和语法分析工具,本篇我们来看看如何借助 Antlr 工具,快速生成词法和语法分析代码. 一.安装 mac 环境: 1)安装 brew install antlr 2) ...

  9. 给你安利一款鲁班大叔开发的maven依赖搜索神器

    写在前面 一款好的插件往往能提高我们的开发效率.今天就给大家安利一款maven 依赖搜索插件. 插件是自己一直关注的鲁班大叔开发的,用了几天真的好用 废话不多说,我们就来看看这是一款什么插件 一.ma ...

  10. 一文带你详细了解HarmonyOS折叠屏设计规范!

    原文:https://mp.weixin.qq.com/s/G25IbfcX2Bq9s1IDPCELGw,点击链接查看更多技术内容. 随着新一代折叠屏手机HUAWEI Mate Xs 2发布,Harm ...