< swiper indicator-dots = "{{indicatorDots}}" interval = "{{interval}}" duration = "{{duration}}" vertical = "true" style = "height:{{windowHeight}}px;width:{{windowWidth}}px" bindchange = "changeVideo" bindtap = "" > < block wx:for = "{{videoList}}" wx:key = "videoList" > < swiper-item > < video id = "myVideo{{index}}" class = "vid" src = "{{item}}" controls = "false" bindtouchstart = "touchVideoStart" bindtouchend = "touchVideoEnd" autoplay = "{{index == current}}" ></ video > </ swiper-item > </ block > </ swiper > |
/** * 开始滑动 */ touchVideoStart: function (e) { console.log( 'touchVideoStart' , e); let video = e.currentTarget.id; console.log( 'video' , video); debugger this .videoContext = wx.createVideoContext(video); //videoContext报错 undefind console.log( 'videoContext' , videoContext); this .videoContext.pause(); }, |
需求是做成像抖音或者快手一样是视频滑动的时候控制上一个视频停止和下一个视频播放
目前运行此代码报错信息为:
videoContext is not defined; [Component] Event Handler Error @ index/index#bound touchVideoStart
ReferenceError: videoContext is not defined
导致报错的原因是什么?还有就是有更好的解决需求方案么?最好是不花钱,谢谢。
this
.videoContext没定义啊,你是在哪里定义的。要先在页面上const定义
在bindtap上直接绑定下面的时间 触发停止有效
pause(){
this.videoContext = wx.createVideoContext('myVideo');
this.videoContext.pause();
},