有2個組件,A組件和B組件,A組件中有一個播放器,并且添加了播放器的播放和停止事件,要求B組件的多個按鈕點擊也能讓A組件的播放器播放,而且是每點擊一個就會暫停上一個,立刻播放下一個這個是A組件
<img :src="start" alt="#" @click="changestart" class="seta">
changestart() { if (this.start == "../../static/pic/start.png") { this.start = "../../static/pic/stop.png"; this.$refs.player.play();
} else { this.start = "../../static/pic/start.png"; this.$refs.player.pause();
}這個是b組件,也添加了click事件,還有其他功能
<li v-for="(songNamelist,songIndex) in songName" v-bind:key="songIndex" class="songlist" @click="songChoose(songIndex,'/play')">
songChoose(songIndex,z) { this.$router.replace(z) this.isresearch = false; this.ishow=false; this.keyword='';
},有一個思路,因為用的是Vuex,點擊B組件按鈕用mutation提交修改state.xxx=true,A組件發(fā)現state的參數xxx=true然后執(zhí)行播放,但是播放的函數不知道寫在哪里這是播放的函數
this.$refs.player.play()寫到created里面不行,因為A沒有重新加載,寫到A的methods里面不知道該用什么來觸發(fā),watch也試過,xxx不知道該在哪里設置為false,請給一個解決方法或一個思路,非常感謝。
Vue 組件之間的控制
慕村9548890
2018-08-18 16:17:43