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

})

},

}

相关推荐
传人once7 小时前
页面中心圆圈放大效果如何写
开发语言·javascript·ecmascript
用户033307413958 小时前
TypeScript using 与 AsyncDisposableStack:在真实服务端代码中协调多资源清理
前端
web3d5208 小时前
Vue3 地图白屏排查清单:容器、弹窗与 ol-viewport 重复创建
vue.js·gis
daisychey8 小时前
用 Playwright 做多平台内容分发,我踩过的 8 个坑
前端
IT_陈寒9 小时前
为什么你应该学习JavaScript?
前端·人工智能·后端
大龄秃头程序员9 小时前
iOS冷启动监控Demo
前端
光影少年9 小时前
为什么 JavaScript 中 0.1 + 0.2 !== 0.3,如何让其相等?
前端·javascript·算法
掘金酱10 小时前
[稀土掘金 × 火山引擎] AI用量周榜冲刺赛|获奖名单公示
前端·人工智能·后端
泡泡oO10 小时前
“如果你还在用Superpowers,那我不要和你说话”
前端·后端·全栈
维克兜率天10 小时前
趋势过滤:避免被“假突破“反复打脸
前端