背景
项目中需要查看一个零件图,需要实现图片的滚轮缩放,鼠标拖拽功能,类似百度地图的拖拽和缩放功能,实现方式如下:
1、父组件
<template>
<div class="box">
<ImageView ref="ImageViewRef" :imageUrl="url" />
<button class="btn-box" @click="reset">重置</button>
</div>
</template>
<script>
import ImageView from './ImageViewr.vue'
export default {
components: {
ImageView
},
data() {
return {
url: 'https://ts1.tc.mm.bing.net/th?id=ORMS.EBNm8u94OA0h0A&w=612&h=304&qlt=90&c=1&rs=1&dpr=1.5&p=0'
}
},
methods: {
reset() {
this.$refs.ImageViewRef.resetImage()
}
}
}
</script>
<style lang="scss" scoped>
.box {
width: 500px;
height: 400px;
border: 1px solid red;
.btn-box {
position: absolute;
top: 320px;
}
}
</style>
