Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit c07977f

Browse files
committed
修复 - 第一次插入歌单时,playlist 组件意外触发 scrollToCurrentSong
在 currentSong 的 watcher 中添加 !this.hasShowPlaylist 验证,防止在第一次触发 watcher 时,因还未引入 $refs 对象,而引发报错
1 parent 41e5ffc commit c07977f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/components/parts-playlist/parts-playlist.vue

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ export default {
7676
methods: {
7777
deleteAllSongs () {
7878
this.deleteAllSongsFromList()
79-
80-
if (!this.playlist.length) {
81-
this.closePlaylist()
82-
}
79+
this.closePlaylist()
8380
},
8481
8582
deleteSong (song, index) {
@@ -92,13 +89,10 @@ export default {
9289
},
9390
9491
scrollToCurrentSong (current) {
95-
const index = this.sequenceList.findIndex(item => {
96-
return current.id === item.id
97-
})
98-
99-
this.$nextTick(() => { // 防止第一次点击时,$refs.playlistItem 为 undefined
100-
this.$refs.contentScroll.scrollToElement(this.$refs.playlistItem[index], 300)
92+
const index = this.sequenceList.findIndex((song) => {
93+
return song.id === current.id
10194
})
95+
this.$refs.contentScroll.scrollToElement(this.$refs.playlistItem[index], 300)
10296
},
10397
10498
getCurrentIcon (item) {
@@ -145,7 +139,7 @@ export default {
145139
146140
watch: {
147141
currentSong (newSong, oldSong) {
148-
if (!this.showPlaylist || newSong.id === oldSong.id) {
142+
if (!this.hasShowPlaylist || newSong.id === oldSong.id) {
149143
return
150144
}
151145

0 commit comments

Comments
 (0)