<template>
<div id="player"></div>
</template>
<script>
export default {
data() {
return {
vodPlayerJs: 'https://player.polyv.net/script/player.js',
vid: '去保利威后台自己拿一个'
}
},
mounted() {
this.loadPlayerScript(this.loadPlayer)
},
methods: {
loadPlayerScript(callback) {
if (!window.polyvPlayer) {
const myScript = document.createElement('script')
myScript.setAttribute('src', this.vodPlayerJs)
myScript.onload = callback
document.body.appendChild(myScript)
} else {
callback()
}
},
loadPlayer() {
const polyvPlayer = window.polyvPlayer
this.player = polyvPlayer({
wrap: '#player',
width: 800,
height: 533,
vid: this.vid
})
}
},
destroyed() {
if (this.player) {
this.player.destroy()
}
}
}
</script>
转载至:https://www.jianshu.com/p/adc8dd7f01d2