当前位置:   article > 正文

vue电子签名_elementui 电子签名

elementui 电子签名

vue电子签名


用vue,canvas实现 h5电子签名。在移动端上需要在获取当前页面的绝对位置。才不会导致touch事件的偏移。代码如下:

<!--html-->
<template>
       <div class="canvasBox" ref="canvasHW">
           <canvas
               @touchstart="touchStart"
               @touchmove="touchMove"
               @touchend="touchEnd"
               ref="canvasF"
               @mousedown="mouseDown"
               @mousemove="mouseMove"
               @mouseup="mouseUp"
           ></canvas>
           <div class="btnBox">
               <button @click="overwrite">重写</button>
               <button>提交签名</button>
           </div>
       </div>
</template>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
<script>
//js
import axios from "axios";
export default {
   
    name: "signature",
    data() {
   
        return {
   
            points: [],
            canvasTxt: null,
            stage_info: [],
            startX: 0,
            startY: 0,
            moveY: 0,
            moveX: 0,
            endY: 0,
            endX: 0,
            w: null,
            h: null,
            isDown: false
        };
    },
    created() {
   },
    mounted() {
   
        let canvas = this.$refs.canvasF;
        canvas.height = this.$refs.canvasHW.offsetHeight - 460;//此处修改canvas高度
        canvas.width = this.$refs.canvasHW.offsetWidth - 10;
        this.canvasTxt = canvas.getContext("2d");
        this.stage_info = canvas.getBoundingClientRect();
    },
    components: {
   
        NavPublic
    },
    methods: {
   
        backHome() {
   
            window.history.back();
        },
        //电脑设备事件
        mouseDown(ev) {
   
            ev = ev || event;
            ev.preventDefault();
            console.log(ev);
            if (ev) {
   
                let obj = {
   
                    x: ev.offsetX,
                    y: ev.offsetY
                };
                console.log(obj);
                this.startX = obj
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签