只修改3视图文件
文件夹位置放的相同 就不用改相对地址

  1. npm install vue-signature-simple
  2. 文件名index.jsmain.js同级
import VueSignature from './src/components/vue-signature'if (typeof window !== 'undefined' && window.Vue) {window.Vue.component('vue-signature', VueSignature)
}VueSignature.install = function (Vue) {Vue.component(VueSignature.name, VueSignature)
}export default VueSignature
  1. 视图文件 layout .vue
<template><div class="home"><div class="container"><div class="section-1"><div class="row"><div class="col"><vue-signatureref="s1":width="width":height="height":stroke-size="strokeSize":stroke-color="strokeColor"/><ul class="colors"><liclass="color":style="{ background: item }"@click="changeColor(item)"v-for="item in colors":key="item":class="{ active: strokeColor === item }"></li></ul></div><!-- 图片 --><div class="col"><img :src="signature" alt="signature" v-if="signature" class="signature"><div class="signature" :style="{ width: (parseInt(width) + 2) + 'px', height: (parseInt(height) + 2) + 'px' }" v-else></div></div></div><div class="btns"><button @click="deleteImg">clear</button><button @click="getSignature">get signature</button></div></div></div></div>
</template><script>
import VueSignature from '../../index'
export default {name: 'App',components: {VueSignature},data () {return {signature: '',strokeColor: '#000',strokeSize: 2,width: 400,height: 150}},methods: {getSignature () {this.signature = this.$refs.s1.getSignature()},deleteImg () {this.$refs.s1.clear()this.signature = ''}}
}
</script><style lang="scss">
</style>
  1. components内添加 vue-signature.vue 文件
    文件内容
<template><div class="vue-signature" :style="{ width: width + 'px', height: height + 'px' }"><canvas:id="id":width="width":height="height"@mousedown.prevent="mouseDown"@mouseup.prevent="mouseUp"@mouseout.prevent="mouseUp"@mousemove.prevent="mouseMove"@touchstart.prevent="mouseDown"@touchmove.prevent="mouseMove"@touchend.prevent="mouseUp"@touchcancel.prevent="mouseUp">Your browser doesn't support canvas</canvas></div>
</template><script>
/*** random string* @param num string length* @returns {string}*/
function randomString (num) {const str = '82gwp7a9e0tzvsqrjy3kubif6l5cnodxhm41'const arr = str.split('')let randomString = ''for (let i = 0; i < num; i++) {const index = Math.floor(Math.random() * str.length)randomString += arr[index]}return randomString
}export default {name: 'vue-signature',props: {height: {default: 100},width: {default: 300},strokeColor: {default: 'black',type: String},strokeSize: {default: 2}},data () {return {id: 'vue-signature-' + randomString(5),isMouseDown: false,lastLocation: {x: 0,y: 0},log: [],empty: true}},methods: {/*** initialization*/init () {this.canvas = document.getElementById(this.id)this.context = this.canvas.getContext('2d')},/*** Clear canvas*/clear () {this.context.clearRect(0, 0, this.width, this.height)this.empty = true},/*** coordinate transformation* @param x* @param y* @returns {{x: number, y: number}}*/coordinateTransfer (x, y) {const box = this.canvas.getBoundingClientRect()return {x: Math.round(x - box.left),y: Math.round(y - box.top)}},/*** Start writing* @param e*/mouseDown (e) {const clientX = e.clientX || e.changedTouches[0].clientXconst clientY = e.clientY || e.changedTouches[0].clientYthis.isMouseDown = truethis.lastLocation = this.coordinateTransfer(clientX, clientY)},/*** Pause writing* @param e*/mouseUp (e) {this.isMouseDown = false},/*** Writing* @param e*/mouseMove (e) {if (this.isMouseDown) {const clientX = e.clientX || e.changedTouches[0].clientXconst clientY = e.clientY || e.changedTouches[0].clientYconst currentLocation = this.coordinateTransfer(clientX, clientY)const context = this.contextconst lastLocation = this.lastLocation// drawcontext.beginPath()context.moveTo(lastLocation.x, lastLocation.y)context.lineTo(currentLocation.x, currentLocation.y)context.strokeStyle = this.strokeColorcontext.lineWidth = Number(this.strokeSize)context.lineCap = 'round'context.lineJoin = 'round'context.stroke()this.lastLocation = currentLocationthis.empty = false}},/*** Get Base64 data of signature image* @param format* 1. image/png (default)* 2. image/jpeg* 3. image/svg+xml* @returns {string}*/getSignature (format) {format = format || 'image/png'return this.canvas.toDataURL(this.format, 1)},/*** is empty ?* @returns {boolean}*/isEmpty () {return this.empty}},mounted () {this.init()}
}
</script><style lang="scss" scoped>
.vue-signature canvas {display: block;background: #efefef;
}
</style>

vue signature 电子签名相关推荐

  1. vue 实现电子签名功能 支持生成图片

    start 最近遇到需求,说是要在前端页面,做一个电子签名的功能. 以前番茄玩过不少canvas的demo,这玩意我第一反应就是canvas. 简单记录一下这个功能. github 自己造轮子有点麻烦 ...

  2. 密码学哈希函数_哈希函数在密码学中的应用

    密码学哈希函数 A Hash Function is a mathematical function that converts a numerical value into another comp ...

  3. [SAP Dictionary]

    Words    Chinese (foreign) exchange gain 汇兑收益 (foreign) exchange loss 汇兑损失 (investment) support allo ...

  4. 关于“量变”和“质变”的圣贤语录与辩证思考

    中国圣贤:天下大事必作于细,天下难事必作于易. 合抱之木,生于毫末:九层之台,起于累土:千里之行,始于足下. 不积跬步,无以至千里.不积小流,无以成江海. 夫风生于地,起于青苹之末.风起于青萍之末,浪 ...

  5. vue中使用电子签名

    使用vue-cli4脚手架,js-signature 2.0.0(https://www.npmjs.com/package/jq-signature)jquery 3.4.1. 1.安装jq及js- ...

  6. 【电子签名手机-vue】

    电子签名手机-vue <template><div class="signature" @touchmove.prevent><div class=& ...

  7. VUE解决微信签名,SPA微信invalid signature问题,完美处理

    深度解决方案,包教不包会,只因为踩坑无数,希望大家能有所收获 前端小菜鸟,因为项目要对接微信的jssdk,对接就需要签名认证,但是无奈安卓和IOS各有各的坑,本篇文章只讨论签名,和一个分享的坑,希望大 ...

  8. Web前后端笔记-vue封装http请求添加signature及后端(Java)解析并验证

    首先帖下运行截图: 签名过期情况: 签名错误情况: 这里npm要导入js-md5,并且在main.js中添加 import md5 from 'js-md5' Vue.prototype.$md5 = ...

  9. vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 “invalid signature“错误解决方案

    vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 "invalid signature"错误解决方案 参考文章: (1)vue 单页面(SPA) hist ...

最新文章

  1. docker 使用python 镜像运行python脚本
  2. 63. Unique Paths II
  3. oracle中rac是什么意思,Oracle中HA、RAC、Datagurad区别
  4. LINUX查看进程开始时间、结束时间、运行时间
  5. exchange 20132016配置使用IMAPPOP
  6. 序列化模块和hashlib模块
  7. 曲奇云盘资源搜索引擎_曲奇云盘下载-曲奇云盘官网版v3.2.4-sosyes
  8. Flarum正式版 简体中文语言包
  9. C语言-排序中的快速排序(简称快排)
  10. Key(Windows Android),申请 android google 地图 API key(转)
  11. 子标签获取父级Id值
  12. 免费H5页面制作工具大汇总
  13. SDU程序设计思维实践题目总结
  14. Echarts 柱状图横向展示和竖向展示
  15. OBS录屏闪动问题解决方案
  16. f16_Automated Trading strategy_Kelly Criterion投资比_Vectorized Backtest_drawndown_value-at-risk_socket
  17. 如何优化SEO的网站结构
  18. java向kafka推送数据_Java kafka消息的发送与接收
  19. 武汉星起航跨境电商到底靠不靠谱?亚马逊跨境收款方式有哪些?
  20. C++简易计算器的实现

热门文章

  1. 【C++ 七】类和对象:封装、继承、多态、友元、运算符重载
  2. JMM~Java Memory Model
  3. flex布局中使用flex-wrap实现换行
  4. python中换行的转义符_Python中的转义符\
  5. 每天学习一点点之字符编码
  6. 使用 React18 + Vite + TypeScript 完成公司项目经验总结,学到了很多
  7. 深度学习之——反向传播
  8. 用户注册登录-交互设计分析
  9. css能实现哪些动画,推荐9款使用CSS3实现的超酷动画效果
  10. 此主机支持 AMD-V,但 AMD-V 处于禁用状态