0👍
You should track when your module is being hot replaced, and when it is just stop the audio player.
<audio id="music" ref="player" autoplay loop>
<source
:src="musicfilename"
type="audio/mp3"
/>
</audio>
export default {
...
mounted() {
if (module.hot) {
module.hot.dispose(this.hmrHandler);
}
},
destroyed() {
if (module.hot) {
module.hot.removeDisposeHandler(this.hmrHandler)
}
},
methods: {
hmrHandler() {
const { player } = this.$refs
player.pause()
// Lines below can also help
// player.currentTime = 0
// player.src = ''
},
},
...
}
Update:
Howler.unload()
placed in the mounted
hook solved the problem.
Look at dispose
and removeDisposeHandler
.
- [Vuejs]-How to translate ITEM using the Vue i18n library
- [Vuejs]-Can't dispatch action defined in store sub file
Source:stackexchange.com