我正试图停止播放音频,但这只是工作一次。
在 Player.vue 组件中,我停止播放音频:
stop() {
this.audio.currentTime = 0;
this.audio.pause();
this.isPlaying = false;
this.$store.commit('stopStatus', this.currentSong.id);
this.$store.commit('playingStatus', false);
},
Vuex :
export const state = () => ({
stop: false
});
export const mutations = {
stopStatus(state, val) {
state.stop = val;
},
};
export const getters = {
getStopStatus: state => state.stop,
};
Index.vue 在已安装的挂钩中:
this.$store.watch(
state => {
return this.$store.getters.getStopStatus;
},
val => {
if (val === this.song.id) {
this.WaveSurfer.stop();
this.WaveSurfer.setCurrentTime(0);
this.icon = false;
}
}
);