思路:
點擊刷新時,用v-if將video元素隱藏,改變一個值,並在watch里監聽這個值,值改變的時候
<live-player id="live-video" :src="dataObj.serverAddress" v-if="showVideo" autoplay></live-player>
refresh(){ console.log("刷新視頻") this.refreshdata+=1; this.showVideo = false; }
將showVideo變為true的方法放在this.$nextTick()中,觸發瀏覽器的重排,可以使瀏覽器重新獲取video和live-player的src值,重新加載視頻資源。
watch:{ refreshdata (old,new) { this.$nextTick(() => { this.showVideo = true }) } },