vue-signature-pad電子簽名插件如何使用

vue-signature-pad在vue中实现电子签名效果
vue-signature-pad官网

npm install --save vue-signature-pad
import Vue from "vue";
import VueSignaturePad from "vue-signature-pad";
Vue.use(VueSignaturePad);
  <template>
  <el-dialog
    :title="mainTitle"
    :visible.sync="editVisible"
    :modal-append-to-body="false"
    width="840px"
    @open="dlgOpen"
    @closed="dlgClosed"
    :close-on-click-modal="false"
  >
    <div id="app">
      <div class="container">
        <div class="row">
          <div class="col-12 mt-2">
            <VueSignaturePad
              id="signature"
              width="95%"
              height="400px"
              ref="signaturePad"
              :options="options"
            />
          </div>
        </div>
        <el-row>
          <el-col :span="4">
            <div class="grid-content bg-purple">
              <el-button type="primary" plain @click="undo">撤销</el-button>
            </div>
          </el-col>
          <el-col :span="4"
            ><div class="grid-content bg-purple-light">
              <el-button type="success" plain @click="save">保存</el-button>
            </div>
          </el-col>
          <el-col :span="4"
            ><div class="grid-content bg-purple">
              <el-button type="warning" plain @click="change">换色</el-button>
            </div>
          </el-col>
          <el-col :span="4"
            ><div class="grid-content bg-purple-light">
              <el-button type="danger" plain @click="resume">重置</el-button>
            </div>
          </el-col>

          <el-col :span="4"
            ><div class="grid-content">
              <el-button type="danger" plain @click="close">关闭</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      editVisible: false,
      mainTitle: "用户签名",
      options: {
        penColor: "#000",
        minWidth: 1,    //控制画笔最小宽度
        maxWidth: 1,    //控制画笔最大宽度
      },
    };
  },
  methods: {
  //显示
    init(id) {
      this.editVisible = true;
    },
    //撤销
    undo() {
      this.$refs.signaturePad.undoSignature();
    },
    //保存
    save() {
      const { isEmpty, data } = this.$refs.signaturePad.saveSignature();

      alert("Open DevTools see the save data.");
      console.log(isEmpty);
      console.log(data);
    },
    //切换颜色
    change() {
      if (this.options.penColor == "#00f") {
        this.options = {
          penColor: "#c0f",
        };
      } else {
        this.options = {
          penColor: "#00f",
        };
      }
    },
    //清除重置
    resume() {
      this.$refs.signaturePad.clearSignature();
    },
    //关闭
    close() {
      this.editVisible = false;
    },
  },
};
</script>
<style lang="scss" scoped>
#signature {
  border: double 3px transparent;
  border-radius: 2px;
  background-image: linear-gradient(white, white),
    radial-gradient(circle at top left, #4bc5e8, #9f6274);
  background-origin: border-box;
  background-clip: content-box, border-box;
  margin-bottom: 15px;
  margin-left: 19px;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值