diff --git a/src/components/search.vue b/src/components/search.vue index 7c86069..8aaa03a 100644 --- a/src/components/search.vue +++ b/src/components/search.vue @@ -114,7 +114,7 @@ export default { } }, methods: { - onInput: debounce(function(value) { + onInput: debounce(function (value) { if (!value.trim()) { return } @@ -153,7 +153,7 @@ export default { img: picUrl }) this.startSong(song) - this.setPlaylist({ data: [song] }) + this.addToPlaylist(song) }, onClickPlaylist(item) { const { id } = item @@ -161,7 +161,7 @@ export default { this.searchPanelShow = false }, ...mapMutations(["setPlaylist"]), - ...mapActions(["startSong"]) + ...mapActions(["startSong", 'addToPlaylist']) }, computed: { suggestShow() { diff --git a/src/store/actions.js b/src/store/actions.js index f3df409..9335f60 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -42,7 +42,9 @@ export default { addToPlaylist({ commit, state }, song) { const { playlist } = state const copy = playlist.slice() - copy.unshift(song) - commit('setPlaylist', { data: copy }) + if (!copy.find(({ id }) => id === song.id)) { + copy.unshift(song) + commit('setPlaylist', { data: copy }) + } } }