canvas 清除数据回退不能使用?

1.回退方法 reBack_fun(){

            let _this = this;
            this.redo_index = this.redo_index - 1;
            if(this.redo_index > 0){
                let _img = new Image();
                _img.src = '';
                _img.src = this.imgCach_arr[this.redo_index - 1];
                console.log(this.imgCach_arr,this.redo_index - 1);
                // this.currentIndex = _len;
                _img.onload = function(){
                    _this.ctx.drawImage(_img,0,0);
                }
            }
        },
  1. 清除方法
    clearImg_arr(){

            console.log(1)
            let _this = this;
            this.imgCach_arr = [];   //清除图片的存储
            this.ctx.clearRect(0, 0, this.casWidth, this.casHeight);
        },   
        

3.每当清除之后就不能使用,什么原因?

阅读 1.8k
1 个回答

是不是你这一句
this.imgCach_arr = []
把所有数据都给清除了,导致回退加载不到资源

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题