//height:自定义canvas的高度,如果不设置的话默认展示图片的宽度
//disabled:设置canvas不允许编辑
//imgSrc:设置背景图连接base64
//rectListData:矩形数组,可在父组件通过watch监听到变化
//initHeatMap:父组件通过this.$refs调用初始化函数
<template>
<div :style="{marginRight:'50px',width:imgWidth<width?imgWidth+'px':width+'px',height:height?height+'px':imgHeight+'px',position:'relative'}">
<canvas id="myCanvas"
:width="width?width+'px':imgWidth+'px'"
:height="height?height+'px':imgHeight+'px'"
@mousedown="mousedown"
@mousemove="mousemove"
@mousewheel="mousewheel"
></canvas>
<!-- y轴滚动条 -->
<div
:style="{height:height?height+'px':imgHeight+'px',overflowY:'scroll',overflowX:'hidden',position:'absolute',right:'-15px'}"
@scroll="handleScrollY($event)"
ref="scrollBarWrapY"
v-show="height && imgHeight > height"
>
<div class="scrollBar" style="width:20px" ref="scrollBarY"></div>
</div>
<!-- x轴滚动条 -->
<div
:style="{width:width?width+'px':imgWidth+'px',overflowX:'scroll',overflowY:'hidden',position:'absolute',right:'-15px'}"
@scroll="handleScrollX($event)"
ref="scrollBarWrapX"
v-show="width && imgWidth > width"
>
<div class="scrollBar" style="width:20px" ref="scrollBarX"></div>
</div>
</div>
</template>
<script>
export default{
props:{
height:{
type:Number
},
width:{
type:Number
},
imgSrc:{
vue+canvas实现区域框选功能
于 2023-02-10 15:01:45 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)