参考konva官网

<template>
  <v-stage ref="stage" :config="stageConfig" @wheel="wheelForScale($event)">
    <v-layer ref="layer">
      <v-image :config="{
            image: image
          }"/>
    </v-layer>
  </v-stage>
</template>

<script>
const width = window.innerWidth;
const height = window.innerHeight;

export default {
  data() {
    return {
      stageConfig: {
        width: width,
        height: height,
        // 拖拽
        draggable: true
      },
      image: null
    };
  },
  created() {
    const image = new window.Image();
    image.src = "https://konvajs.org/assets/yoda.jpg";
    image.onload = () => {
      // set image only when it is loaded
      this.image = image;
    };
  },
  methods: {
    // 放大缩小
    wheelForScale(e) {
    
      //document.getElementById('ele').addEventListener('mousewheel', function (e) {
      // e.preventDefault();
      //}, { passive: false }); 
      
      if (e.evt.wheelDelta > 0) {
        let i = 1
        this.stageConfig.width += i * 100
        i++
      }else {
        let i = 1
        this.stageConfig.width += i * -100
        i++
      }
    }
  }
};
</script>
Logo

前往低代码交流专区

更多推荐