vue实现签字板

作者: 吃肉肉不吃肉肉 | 来源:发表于2022-02-08 15:47 被阅读0次
效果
1644306323(1).png
点击预览
1644306522(1).png
安装:

npm install vue-esign --save

使用:

在main.js中引入

import vueEsign from 'vue-esign'
Vue.use(vueEsign)
实现源码
<template>
  <div class="page-content">
    <div class="content">
      <vue-esign ref="esign" :width="800" :height="500" :line-width="8" line-color="#000" bg-color="#FFF" />
    </div>
    <div class="flex">
      <el-button type="danger" @click="handleReset">重签</el-button>
      <el-button type="primary" @click="handleGenerate">预览</el-button>
      <el-button type="success" @click="handleGenerate">确认</el-button>
    </div>
    <el-image-viewer
      v-if="showViewer"
      :on-close="()=>{showViewer=false}"
      :url-list="[resultImg]"
    />
  </div>
</template>
<script>
export default {
  components: {
    'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer') // 预览签名图片的插件,无需下载,elementui自带
  },
  data() {
    return {
      lineWidth: 8, // 画笔粗细
      lineColor: '#000', // 画笔颜色
      bgColor: '#fff', // 画布背景颜色
      isCrop: false, // 是否剪裁
      showViewer: false, // 预览签名
      resultImg: '' // base64图片
    }
  },
  methods: {
    handleReset() {
      this.$refs['esign'].reset() // 清空画布
    },
    handleGenerate() {
      this.$refs['esign'].generate().then(res => {
        this.resultImg = res // 得到了签字生成的base64图片
        this.showViewer = true
      }).catch(() => { // 没有签名,点击生成图片时调用
        this.$message({
          message: '未签名!',
          type: 'warning'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .content {
    border: 1px solid #f1f1f1;
  }
  .flex {
    margin: 10px;
    display: flex;
    align-content: center;
  }
</style>

相关文章

  • vue实现签字板

    效果 点击预览 安装: npm install vue-esign --save 使用: 在main.js中引入 ...

  • 移动端使用源生写法编写签字板

    前端时间给大家介绍了通过vue在PC页面上制作签字版,今天给大家介绍移动端签字板的源生写法。 插件链接:https...

  • 空白的签字板

    识人难,又做的是需要在陌生人里,迅速判断某个人的整体能力的事,所以总留心用什么样的方法好。 有一次参加个活动,让大...

  • 手写板,签字版

    1.建一个view .h文件复制以下代码 /** * 画布 */ @interface SKGraphicView...

  • 【微信小程序canvas】实现小程序手写板用户签名(附代码)

    【微信小程序canvas】实现小程序手写板用户签名(附代码) 工作中公司业务需要的微信小程序用户签字功能 先看效果...

  • vue总结

    vue路由守卫 vue实现双向绑定原理 Vue生命周期: vue跨域方式 vue-router实现原理 vue-r...

  • vue实现最简单的日历板

    最近遇到的一个项目需要实现日历板的功能,前期技术准备的时候随手写了一个简版日历板,样式几乎没有,功能也只有月份的切...

  • iOS涂鸦板

    想要实现一个签字板的效果,比如这样: 1、定义一个数组,记录手指路径,数组的一个元素标志一条曲线。每个元素包含:手...

  • vue复制到剪切板

    VUE 中实现复制到剪切板,在电脑任何位置可复制功能 1、环境 2、使用步骤 1) 安装依赖包 引入安装包 页面...

  • js、jQuery、Vue对比

    Javascript jQuery Vue vue可以实现追加

网友评论

    本文标题:vue实现签字板

    本文链接:https://www.haomeiwen.com/subject/mmbbkrtx.html