methods中,首先初始化画布及位置
this.canvas = this.$refs.imgCanvas;
this.context = this.canvas.getContext('2d');
this.rectList = [];
this.imageObj = new Image();
this.imageObj.src = this.imageUrl;
这里是其中一个判断
if (this.isShowBtn && this.canvasControlType === 'button') {
this.canvas.onmousedown = (e) => {
// e.offsetX是鼠标点击到canvas边的位置
this.beginX = e.offsetX;
this.beginY = e.offsetY;
// 把点击的win坐标转为canvas坐标
const Cp = this.convertCoordinate(this.beginX, this.beginY);
// 判断在canvas坐标点上是否在图片上
this.canMove = this.imgIsDown(Cp.x, Cp.y);
this.canvas.onmousemove = (e) => {
const x = e.offsetX;
const y = e.offsetY;
if (!this.canButtonMove) return;