其他分享
首页 > 其他分享> > vue-cli 中使用 保利威 云点播播放视频

vue-cli 中使用 保利威 云点播播放视频

作者:互联网

<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

标签:vue,点播,cli,vid,callback,player,myScript,polyvPlayer,loadPlayerScript
来源: https://www.cnblogs.com/GouHuang/p/16101385.html