背景音乐后台继续vuex数据不同步
var that = this
let tempIndex
//随机
if (that.playWay == 2) {
let temp = Math.floor(Math.random() * this.assetsList.length);
temp === this.assetsList.length - 1 ? (temp) : (temp++)
tempIndex = temp
} else if (that.playWay == 1) { //顺序播放
//顺序
if (this.nowIndex >= (this.assetsList.length - 1)) {
tempIndex = 0
} else {
tempIndex = this.nowIndex + 1
}
} else { //单曲播放 不做处理
if (this.nowIndex >= (this.assetsList.length - 1)) {
tempIndex = 0
} else {
tempIndex = this.nowIndex + 1
}
}
this.$store.commit('song/setSongIndex', tempIndex)
this.bgAudioMannager.startTime = 0
this.$store.commit('song/setSongId', that.assetsList[this.nowIndex].id)
that.bgAudioInnit()
然后在bgAudioInnit这个方法中,vuex中的setSongIndex设置的索引有问题。并没有变化。这种问题只在把小程序背景音乐放入后台才会出现。其他情况不会发生