vue 实现签字功能

1、安装:npm install vue-esign --save

2、main.js文件中全局引入:

// 签字

import vueEsign from 'vue-esign'

Vue.use(vueEsign)

3、页面内容

<vue-esign ref="esign" :width="800" :height="300" :isCrop="isCrop" :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" />

<button @click="handleReset">清空画板</button>

<button @click="handleGenerate">生成图片</button>

4、说明:

5、

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 // 得到了签字生成的base64图片

let imgFile = this.base64ImgtoFile(res, 'file') //得到文件格式

}).catch(err => { // 没有签名,点击生成图片时调用

this.$message({

message: err + ' 未签名!',

type: 'warning'

})

alert(err) // 画布没有签字时会执行这里 'Not Signned'

})

}

}

6、将base64转化成图片方法:

// 将base64,转换成图片

base64ImgtoFile(dataurl, filename='file') {
const arr = dataurl.split(',')
const mime = arr0.match(/:(.*?);/)1
const suffix = mime.split('/')1
const bstr = atob(arr1)
let n = bstr.length
const u8arr = new Uint8Array(n)

while (n--) {

u8arrn = bstr.charCodeAt(n)

}

return new File(u8arr, `{filename}.{suffix}`, {

type: mime

})

},

}

相关推荐
该用户已成仙5 分钟前
vue3 使用 vuedraggable 报错 TypeError: isFunction2 is not a function
前端·javascript·vue.js
aidou13145 分钟前
Kotlin中实现星级评价选择功能(仅支持整数)
前端·kotlin·自定义view·imageview·ontouchevent·customratingbar
良逍Ai出海8 分钟前
我用 Codex 搭了一个 WordPress 独立站
前端
TPBoreas10 分钟前
前端面试问题打把-场景题
开发语言·前端·javascript
问心无愧051310 分钟前
ctf show web入门159
前端·笔记
San813_LDD10 分钟前
[Vue/HTML]ECharts 使用指南:从入门到绘制各种常用图表
vue.js·html·echarts
恋猫de小郭15 分钟前
Flutter 又为 AI 时代添砖加瓦:全新 ComponentLibrary 提议
android·前端·flutter
就叫_这个吧16 分钟前
HTML或JSP页面链接CSS,link标签没问题,但不显示样式问题解决
java·前端·css·html·intellij-idea·jsp
IT_陈寒20 分钟前
SpringBoot这个坑差点让我加班到天亮
前端·人工智能·后端
小小龙学IT26 分钟前
Rust Web 框架 Axum:轻量级异步的下一代后端利器
前端·驱动开发·rust