解决Cannot read property ‘dp’ of undefined
问题
在使用vue-dplayer
时安装案例代码
mounted() {
const player = this.$refs.player.dp
player.play()
setTimeout(() => {
player.pause()
}, 2000)
结果报错Cannot read property ‘dp’ of undefined
解决过程
当时研究了好久百思不得其解,因为当时是看着一位老哥的demo博客来做的,后来又去源码作者那里看他的example案例,看到index.js时
一抖机灵,我好像没把vue-dplayer这组件注册到vue全局中,那老哥也是只给了vue文件的主要demo代码,也不提醒一下记得到main.js里注册(好吧,我承认是我傻逼忘记引用组件时要走的重要步骤)
import VueDPlayer from './dplayer/vue-dplayer'
// 引入vue-dplayer的依赖DPlayer
Vue.use(VueDPlayer)
记得在main,js里注册!!!