0
点赞
收藏
分享

微信扫一扫

React 之 使用 ref 引用值(七)

白衣蓝剑冰魄 2024-05-07 阅读 10

  由于预订的抓拍方案无法令人满意,于是又回到了直接在WEB抓拍的方案。这个我信心满满,因为之前的代码已经验证过了。

  验证是通过的,想法是简单的,现实是不通的。我一点抓拍按钮,没反应啊。这是怎么回事呢?于是做了一番分析:

  • 具体抓拍代码

VUE dplayer抓拍截图代码-CSDN博客

  • 变量声明
export default {
  name: "flvPlayer",
  data() {
    return {
      dp: null,
......
  • 抓拍代码
this.dp.on('screenshot', function() = {
    ......
    this.canvas.width  = this.dp.video.videoWidth;
    this.canvas.height = this.dp.video.videoHeight;
    ......
});

输出了一下,此时this.dp是undefined。这可怎么办?难道这个回调不能用?

  • 解决办法

我网上搜索了一番,并没有找到解决办法。使用map可以,就是太麻烦。于是我想到了const。

const dplayer = this.dp;

this.dp.on('screenshot', function() = {
    ......
    this.canvas.width  = dplayer.video.videoWidth;
    this.canvas.height = dplayer.video.videoHeight;
    ......
});

举报

相关推荐

0 条评论