新增超出限制,如何新增一个自动替换一个数据

image.png

addCameraList(addCamera) {
      let domain = null;
      if (!addCamera || !addCamera.length) {
        this.cameraList.forEach((vo, idx) => {
          this.removeScreenCamera(idx);
        });
        this.cameraList = [];
        return false;
      }
      if (this.cameraList.length >= this.size) {
        this.$message.info("超过分屏数量限制!");
        在这我想写如果超出限制,新打开视频替换已打开的视频。不知道该怎么写


      }
      if (this.cameraList.indexOf(addCamera[0]) >= 0) {
        this.$message.info("视频已存在!");
        return false;
      }
      this.cameraList.push(addCamera[0]);
      this.$forceUpdate();
      this.$nextTick(() => {
        this.cameraPlay(this.cameraList.length - 1, addCamera[0]);
      });
    },
阅读 1.2k
1 个回答
addCameraList(addCamera) {
      let domain = null;
      if (!addCamera || !addCamera.length) {
        this.cameraList.forEach((vo, idx) => {
          this.removeScreenCamera(idx);
        });
        this.cameraList = [];
        return false;
      }
      if (this.cameraList.indexOf(addCamera[0]) >= 0) {
        this.$message.info("视频已存在!");
        return false;
      }
      this.cameraList.push(addCamera[0]);
      // 个人觉这里比较合适
      if (this.cameraList.length >= this.size) {
        this.$message.info("超过分屏数量限制!");
        //在这我想写如果超出限制,新打开视频替换已打开的视频。不知道该怎么写
        this.cameraList = this.cameraList.slice(-this.size)
      }
      this.$forceUpdate();
      this.$nextTick(() => {
        this.cameraPlay(this.cameraList.length - 1, addCamera[0]);
      });
    },
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题