功能

  1. 兼容 PC 和 Mobile;
  2. 画布自适应屏幕大小变化(窗口缩放、屏幕旋转时画布无需重置,自动校正坐标);
  3. 自定义画布尺寸(导出图尺寸),画笔粗细、颜色,画布背景色;
  4. 支持裁剪 (针对需求:有的签字需要裁剪掉四周空白)。
  5. 导出图片格式为 base64;
  6. 示例demo

安装—插件

  1. npm install --save vue-esign

使用

  1. **mian.js** 中引用

    1. import vueEsign from 'vue-esign'
    2. Vue.use(vueEsign)
  2. 页面中使用 必须设置 ref ,用来调用组件的两个内置方法** reset() **** generate()**
    无需给组件设置 style 的宽高,如果画布的 width属性值没超出父元素的样式宽度,则该组件的样式宽度就是画布宽度,超出的话,组件样式宽度则是父元素的100%; 所以只需设置好父元素的宽度即可 ```vue

data () { return { lineWidth: 6, lineColor: ‘#000000’, bgColor: ‘’, resultImg: ‘’, isCrop: false } }, methods: { handleReset () { this.$refs.esign.reset() }, handleGenerate () { this.$refs.esign.generate().then(res => { this.resultImg = res }).catch(err => { alert(err) // 画布没有签字时会执行这里 ‘Not Signned’ }) } }

  1. 3. 说明:两个内置方法,通过给组件设置 **ref** 调用:
  2. ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22000767/1646028709455-9c06fc8a-bf19-4b47-a45a-83900a33eb27.png#clientId=ucf9ab081-8850-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=322&id=u06f1aa2f&margin=%5Bobject%20Object%5D&name=image.png&originHeight=322&originWidth=811&originalType=binary&ratio=1&rotation=0&showTitle=false&size=243182&status=done&style=none&taskId=u195552a6-9601-4933-98d3-e86e10a75db&title=&width=811)
  3. 4. **清空画布**
  4. ```vue
  5. this.$refs.esign.reset()
  1. 生成图片 ```vue this.$refs.esign.generate().then(res => { console.log(res) // base64图片 }).catch(err => { alert(err) // 画布没有签字时会执行这里 ‘Not Signned’ })

```