使用Nuxt编写全局客户端mp3播放器 .
需要像这样创建和销毁咆哮插件实例:
组件MusicList
...
handlePlayPause: function(index, nowActive) {
if (nowActive) {
if (this.pause) {
this.$store.dispatch('playlist/unsetPause')
this.$playerInstance.play()
} else {
this.$store.dispatch('playlist/setPause')
this.$playerInstance.pause()
}
} else {
const track = this.$props.tracks[index];
this.setTrack(track);
if (this.$playerInstance) {
this.$playerInstance.destroy();
}
this.$playerInstance = howlerPlugin.createPlayerInstance();
this.$playerInstance.play();
}
},
在其他站点组件中,我需要访问playerInstance
一种方法是在window.pluginInstanse中存储$ playerInstance第二种方式存储在Vuex商店中的playerInstance .
还有什么选择?可能与nuxt插件或模块?