1.0.2 • Published 3 years ago

vue-image-annotation v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

vue-image-annotation

vue 图片批注组件

demo

示例

demo https://wawjqyh.github.io/vue-image-annotation/

安装

npm

$ npm install vue-image-annotation

使用

<template>
  <div>
    <button @click="handleOpenDrawer">打开图片</button>
    <VueImageAnnotation ref="refImageDrawer" @onSave="handleSave" />
  </div>
</template>

<script>
import VueImageAnnotation from 'vue-image-annotation';

export default {
  components: { VueImageAnnotation },

  methods: {
    handleOpenDrawer() {
      // 通过 openUrl 打开批注工具,传入需要批注的图片的地址
      this.$refs.refImageDrawer.openUrl('./img.jpeg');
    },

    // 点击保存时,会将批注后的图片内容通过两种格式返回
    handleSave(base64, file) {
      console.log(base64);
      console.log(file);
    }
  }
};
</script>

Methods

方法名说明参数
openUrl打开图片批注组件,传入图片 urlurl|String: 图片地址
openBase64打开图片批注组件,传入 base64 格式图片内容base64|String: base64 格式图片内容

注意:

openUrl 内部使用 fetch 获取图片内容,获取后添加到 canvas 中。请注意跨域问题

如果使用 openUrl 遇到问题,可以尝试自行获取图片内容,转成 base64 后通过 openBase64 方法打开组件

Events

事件名称说明回调参数
onSave保存图片时触发base64|String: base64 格式图片内容
file|String: 二进制图片内容