<template >
<view class="body">
<canvas ref="canvasId" canvas-id="canvasId" id="canvasId"
style="{width:'3000px',height:'2000px'}"
@mousedown ="mouseDown($event)"
</canvas>
</view>
</template>
<script>
const ctx={}
export default {
data() {
return {}
},
onReady(){
ctx=uni.createCanvasContext('canvasId')
ctx.strokeStyle = 'red';
},
methods: {
mouseDown(e){
let x=e.pageX-e.currentTarget.offsetLeft;
let y= e.pageY-e.currentTarget.offsetTop
ctx.strokeRect(x, y,80,50);
ctx.draw(true)
}
}
}
</script>
0 个回复