feat: 添加 WritingBoard 组件方法

This commit is contained in:
pipipi-pikachu 2022-05-02 18:48:04 +08:00
parent 67bc6f55e1
commit 9ed5a3e708

View File

@ -291,6 +291,21 @@ export default defineComponent({
ctx.clearRect(0, 0, canvasRef.value.width, canvasRef.value.height)
}
// DataURL
const getImageDataURL = () => {
return canvasRef.value?.toDataURL()
}
// DataURL canvas
const setImageDataURL = (imageDataURL: string) => {
const img = new Image()
img.src = imageDataURL
img.onload = () => {
if (!ctx) return
ctx.drawImage(img, 0, 0)
}
}
return {
mouse,
mouseInCanvas,
@ -305,6 +320,8 @@ export default defineComponent({
handleMousemove,
handleMouseup,
clearCanvas,
getImageDataURL,
setImageDataURL,
}
},
})