From 282d721db83060a08352fe469f1a7084025beb22 Mon Sep 17 00:00:00 2001 From: ssh <949589855@qq.com> Date: Tue, 30 Jul 2019 16:50:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=AD=8C=E6=9B=B2=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/search.vue | 6 +++--- src/store/actions.js | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) 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 }) + } } }