收藏
回答

canvas画不了东西了 有大佬给看看么? 昨天发现的 之前一直好好的

"Component "xxx" does not have a method "true" to handle event "touchmove"."

提示这个东西


下面是代码

<canvas @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend" :disable-scroll="true" canvas-id="xkx" id="xkx" style="width: 100%; height: 800rpx;"></canvas>
methods: {
			createCanvas() {
				console.log("创建画")
			    //创建绘图对象
			    this.ctx = uni.createCanvasContext('xkx', this);
			    //设置画笔样式
			    this.ctx.lineWidth = 4;
			    this.ctx.lineCap = 'round';
			    this.ctx.lineJoin = 'round';
			},
			touchstart() {
				 console.log("开始")
				 console.log(e.changedTouches[0].x)
				 console.log(e.changedTouches[0].y)
			     let startX = e.changedTouches[0].x;
			     let startY = e.changedTouches[0].y;
			     let startPoint = { X: startX, Y: startY };
			     this.points.push(startPoint);
			     //每次触摸开始,开启新的路径
			     this.ctx.beginPath();
			},
			touchmove(e) {
				console.log("开始移动")
				console.log(e.changedTouches[0].x)
				console.log(e.changedTouches[0].y)
			     let moveX = e.changedTouches[0].x;
			     let moveY = e.changedTouches[0].y;
			     let movePoint = { X: moveX, Y: moveY };
			     this.points.push(movePoint); //存点
			     let len = this.points.length;
			     if (len >= 2) {
			             this.draw(); //绘制路径
			     }
			},
			true(e) {
				console.log("开始移动")
				console.log(e.changedTouches[0].x)
				console.log(e.changedTouches[0].y)
			     let moveX = e.changedTouches[0].x;
			     let moveY = e.changedTouches[0].y;
			     let movePoint = { X: moveX, Y: moveY };
			     this.points.push(movePoint); //存点
			     let len = this.points.length;
			     if (len >= 2) {
			             this.draw(); //绘制路径
			     }
			},
			touchend() {
			     this.points = [];
			},
			draw() {
				console.log("开始画")
				console.log("开始画")
			     let point1 = this.points[0];
			     let point2 = this.points[1];
			     this.points.shift();
			     this.ctx.moveTo(point1.X, point1.Y);
			     this.ctx.lineTo(point2.X, point2.Y);
			     this.ctx.stroke();
			     this.ctx.draw(true);
			},
			clear() {
			    let that = this;
			    uni.getSystemInfo({
			            success: function(res) {
			                let canvasw = res.windowWidth;
			                let canvash = res.windowHeight;
			                that.ctx.clearRect(0, 0, canvasw, canvash);
			                that.ctx.draw(true);
			            }
			    });
			},
			close(){
				this.$refs.caogao.close();
				this.caogaoflag = false;
			}
}
回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-04-19

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2023-04-19
    有用
    回复
登录 后发表内容