关键字
aliplayer 视频点播时,点击多次视频会造成视频源积累,从而导致视频播放失败,故为防止多次点击导致事件积累,采用函数节流进行相应的限制。
1const Debounce = (fn, t) => { 2 let delay = t || 500, 3 timer = null; 4 return function () { 5 let args = arguments; 6 if (timer) { 7 clearTimeout(timer); 8 } 9 timer = setTimeout(() => { 10 timer = null; 11 fn.apply(this, args); 12 }, delay); 13 }; 14};
1switchVideo: Debounce(function (videoId, isPerchase) { 2 // 获取视频播放密匙 3 this.getKeyInfo(videoId); 4 this.isPerchase = isPerchase == undefined ? true : isPerchase; 5}, 500);