duanzhenzhen

效果图

1.下载:npm install --save signature_pad

2.引入并使用

<template>
  <div>
    <div style="border: 1px solid #eee" ref="canvasBox">
      <canvas class="canvasId"/>
    </div>
    <div class="btnBox">
      <van-button round type="info" @click="clear">重签</van-button>
      <van-button round type="info" @click="save">确定</van-button>
    </div>
  </div>
</template>

<script>
  import SignaturePad from \'signature_pad\';
  import {Button,Notify} from \'vant\'
    export default {
        name: "signature",
      components: {
        [Button.name]:Button,
        [Notify.Component.name]: Notify.Component,
      },
      data () {
        return {
          SignaturePad:null,
          config:{
            penColor: "#000000",   //笔刷颜色
            minWidth:3,       //最小宽度
          }
        }
      },
      mounted() {
        this.getCanvas()
      },
      methods: {
        getCanvas() {
          var canvas = document.querySelector(\'.canvasId\');
          this.signaturePad = new SignaturePad(canvas, this.config);
          canvas.height = 200;
          canvas.width = this.$refs.canvasBox.clientWidth;
        },
        //保存
        save(){
          //默认保存为png格式
          // console.log(this.signaturePad.toDataURL())
          // console.log(this.signaturePad.toDataURL(\'image/jpeg\'))
          // console.log(this.signaturePad.toDataURL(\'image/svg+xml\'))
          // console.log(this.signaturePad.isEmpty())  //判断画布有没有内容,布尔型
          if(this.signaturePad.isEmpty()){
            Notify({ type: \'danger\', message: \'电子签名不能为空\' });
          }else{
            this.$emit(\'setSign\',this.signaturePad.toDataURL())
          }

        },
        //清除
        clear() {
          //清除画布内容
          this.signaturePad.clear();
        },
      }
    }
</script>

<style scoped lang="scss">
  .btnBox {
    padding: 10px;
    text-align: center;
  /deep/ .van-button--info {
    height: 30px;
    padding: 0 30px;
  &:first-child {
     margin-right: 30px;
   }
  }
  }
</style>

 3.父组件接收签名图片

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-09-16
  • 2022-01-17
  • 2021-10-20
猜你喜欢
  • 2022-12-23
  • 2021-09-11
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案