Page({
onReady() {
this.videoCtx = wx.createVideoContext('myVideo')
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({
text: this.inputValue,
color: getRandomColor()
})
}
})
一旦我点击发送弹幕按钮就报错:
thirdScriptError
Cannot read property 'sendDanmu' of undefined;at pages/cover-view/cover-view page bindSendDanmu function
TypeError: Cannot read property 'sendDanmu' of undefined
如果使用 wx.createVideoContext('myVideo').sendDanmu({}) 就没问题
WXML:
看看代码里是否有两个onReady方法
没有用,我的代码中就是 this.videoCtx.sendDanmu,一样不起作用,还是会报错,所以请问各位大侠有解决方案吗?
你创建的对象名叫 videoCtx 下面又用this.videoContext肯定报错啊 改成这样就行了 this.videoCtx.sendDanmu