vue3 实现电子签名

简介: vue3 实现电子签名

vue电子签名可以通过vue-esign插件来实现:

第一步安装:
npm install vue-esign
引用方式:
import vueEsign from ‘vue-esign’
 
createApp(App).use(vueEsign).use(ElementPlus).mount(‘#’app)

使用方式:

<template>
  <!-- 使用这个签名组件 -->
  <vueEsign
    ref="esign"
    class="mySign"
    :width="800"
    :height="300"
    :isCrop="isCrop"
    :lineWidth="lineWidth"
    :lineColor="lineColor"
  />
  <span class="dialog-footer">
    <el-button @click="save" type="primary">生成签字图片</el-button>
    <el-button @click="reset">清空画板</el-button>
  </span>
  <img v-if="resultImg" :src="resultImg" alt="Signature Image" />
</template>
 
<script setup>
import vueEsign from "vue-esign";
import { ref } from "vue";
const lineWidth = ref(0);
const lineColor = ref("#000000");
const bgColor = ref("");
const resultImg = ref("");
const isCrop = ref("");
const esign = ref(null);
 
// 清空画板
const reset = () => {
  esign.value.reset();
  //   this.$refs.esign.reset();
};
// 保存
const save = () => {
  // 可选配置参数 ,在未设置format或quality属性时可在生成图片时配置 例如: {format:'image/jpeg', quality: 0.5}
  // this.$refs.esign.generate({format:'image/jpeg', quality: 0.5})
  esign.value
    .generate()
    .then((res) => {
      //   this.$emit("finsih", res);
      console.log(res);
      resultImg.value = res; 
    })
    .catch((err) => {
      console.log(err);
      // 画布没有签字时会执行这里 'Not Signned'
      //   this.$message.error("您还未完成签字,请签字完成后保存");
    });
};
</script>


相关文章
|
2天前
|
JavaScript 前端开发 CDN
vue3速览
vue3速览
11 0
|
2天前
|
设计模式 JavaScript 前端开发
Vue3报错Property “xxx“ was accessed during render but is not defined on instance
Vue3报错Property “xxx“ was accessed during render but is not defined on instance
|
2天前
|
缓存 JavaScript 前端开发
Vue3 官方文档速通(中)
Vue3 官方文档速通(中)
9 0
|
2天前
|
缓存 JavaScript 前端开发
Vue3 官方文档速通(上)
Vue3 官方文档速通(上)
9 0
|
2天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之五:Pinia 状态管理
Vue3+Vite+Pinia+Naive后台管理系统搭建之五:Pinia 状态管理
7 1
|
2天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之三:vue-router 的安装和使用
Vue3+Vite+Pinia+Naive后台管理系统搭建之三:vue-router 的安装和使用
7 0
|
2天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之二:scss 的安装和使用
Vue3+Vite+Pinia+Naive后台管理系统搭建之二:scss 的安装和使用
6 0
|
2天前
|
JavaScript 前端开发 API
Vue3 系列:从0开始学习vue3.0
Vue3 系列:从0开始学习vue3.0
9 1
|
2天前
|
网络架构
Vue3 系列:vue-router
Vue3 系列:vue-router
8 2
|
2天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之一:基础项目构建
Vue3+Vite+Pinia+Naive后台管理系统搭建之一:基础项目构建
7 1