老师,我有个疑问

来源:11-4 歌曲列表组件播放列表的实现(2)

慕数据7542861

2018-12-19

当播放列playlist表处于display:none状态的时候,为什么我切歌改变当前的currentSong,playlist中确实也监听到了currentSong的变化,但是this.scrollToCurrent()却无法将当前播放的歌曲移到顶部呢?

老师的解决方法在调用show()方法展现playlist的时候,再调用一次this.scrollToCurrent()

写回答

1回答

ustbhuangyi

2018-12-19

能否贴一下相关的代码?

0
1
慕数据7542861
是在vue-music/src/components/playlist/playlist.vue中 watch: { currentSong(newSong, oldSong) { if (!this.showFlag || newSong.id === oldSong.id) { return } setTimeout(() => { this.scrollToCurrent(newSong) }, 20) } }, 监听到歌曲的改变在playlist.vue这个组件处于隐藏的时候,scrollToCurrent()是无法将当前播放的歌曲移动到顶部的。 老师你的解决方案是在show()的时候再执行一次scrollToCurrent() show() { this.showFlag = true setTimeout(() => { this.$refs.listContent.refresh() this.scrollToCurrent(this.currentSong) }, 20) }, 这是什么原因?
2018-12-20
共1条回复

Vue2.0高级应用教学实战,开发企业级移动端音乐Web App

Vue.js高级知识应用大集合,实战企业级APP,教你搞定组件化开发。

5432 学习 · 3805 问题

查看课程