Aliplayer is not defined

436 阅读1分钟

阿里云视频播放器 报错:Aliplayer is not defined

最近发现一个如果在当前页面打开,用了阿里云视频播放器的页面,就会报上面的错。

复现步骤

跳转页面报Aliplayer is not defined错误,需要刷新一下页面才可以正常播放

报错ReferenceError: Aliplayer is not defined at VueComponent.mounted (_vid.vue?0e11:156:1) 显示无法new Aliplayer({})

解决方案

1、确保 new Aliplayer是写在 mounted(){}方法中。

2、确保playAuth可以获取到。

3、也是最重要的一点,就是播放器需要另外打开一个网页用来作播放页面(因为它要加载播放器脚本),如果你只是在当前页面更新路径是不能正常播放的(因为脚本没加载进来,没法创建播放器,这就是为啥刷新一下页面之后就可以正常播放的原因),所以你需要在 跳转链接那里加上target="_blank"

或者在nuxt.config.js中引入这个

link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
],//就是这个位置!!!!!
script:[
    { src: "https://g.alicdn.com/de/prismplayer/2.9.17/aliplayer-min.js",type:"text/javascript"}
]