vue 를 사용 하여 전자 서명 구성 요소 의 예제 코드 를 실현 합 니 다. 6251 단어 vue전자 서명 모듈 생활 속 에서 우리 가 전자 서명 을 가장 많이 사용 하 는 곳 은 아마도 은행 일 것 이다.매번 너 에 게 이름 을 남기 게 할 것 이다.오늘 우 리 는 vue 로 전자 서명 패 널 을 실현 할 것 이다.그림 을 그 리 려 면 첫 번 째 단 계 는 canvas 라벨 을 사용 하 는 것 입 니 다.이전 글 에서 canvas 를 사용 하여 전단 에 그래 픽 인증 코드 를 만 드 는 구성 요 소 를 실 현 했 습 니 다.토 크 되 는 것 이 안전 하지 않 습 니 다.그러면 이 전자 서명 구성 요 소 는 토 크 되 지 않 을 것 입 니 다.canvas탭 은 HTML 5 의 새 탭 입 니 다.탭 은 그래 픽 용기 일 뿐 발 로 그림 을 그 려 야 합 니 다.canvas 태그 자 체 는 그림 그리 기 능력 이 없습니다.모든 그림 그리 기 작업 은 자바 스 크 립 트 내부 에서 이 루어 져 야 합 니 다.canvas 를 사용 하여 그림 을 그 리 는 데 필요 한 몇 가지 절차 가 있 습 니 다.canvas 요 소 를 가 져 옵 니 다canvas 요 소 를 통 해 context 대상 을 만 듭 니 다context 대상 을 통 해 도형 을 그립 니 다현재 전자 서명 수요 에서 서명 은 하나의 선 으로 구성 되 기 때문에 우 리 는 다음 과 같은 몇 가지 방법 을 사용 할 것 이다.beginPath():경 로 를 시작 하거나 현재 경 로 를 초기 화 합 니 다moveto():캔버스 의 지정 점 으로 경 로 를 이동 하고 라인 을 만 들 지 않 습 니 다lineto():새로운 점 을 추가 한 다음 에 캔버스 에 이 점 에서 마지막 으로 지정 한 선 을 만 듭 니 다stroke():정 의 된 경 로 를 그립 니 다closePath():현재 점 에서 시작 점 으로 돌아 가 는 경 로 를 만 듭 니 다이벤트canvas 에 그림 을 그 리 려 면 몇 가지 특정한 사건 을 연결 해 야 합 니 다.이 사건 들 은 pc 쪽 과 핸드폰 쪽 이 다 릅 니 다.pc 엔 드 이벤트 mousedown mousemove mouseup 핸드폰 엔 드 사건 touchstart touchmove touchend 핵심 코드canvas 태그 초기 화 및 귀속 이벤트 <canvas @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" ref="canvasF" @mousedown="mouseDown" @mousemove="mouseMove" @mouseup="mouseUp" ></canvas> 화필 을 얻다mounted 수명 주기 초기 화 mounted() { let canvas = this.$refs.canvasF; canvas.height = this.$refs.canvasHW.offsetHeight - 100; canvas.width = this.$refs.canvasHW.offsetWidth - 10; this.canvasTxt = canvas.getContext("2d"); this.canvasTxt.strokeStyle = this.color; this.canvasTxt.lineWidth = this.linewidth; }이벤트 처리mouseDown // mouseDown(ev) { ev = ev || event; ev.preventDefault(); let obj = { x: ev.offsetX, y: ev.offsetY }; this.startX = obj.x; this.startY = obj.y; this.canvasTxt.beginPath();// this.points.push(obj);// this.isDown = true; }, touchStart // touchStart(ev) { ev = ev || event; ev.preventDefault(); if (ev.touches.length == 1) { this.isDraw = true; // let obj = { x: ev.targetTouches[0].clientX, y: ev.targetTouches[0].clientY - (document.body.offsetHeight * 0.5 + this.$refs.canvasHW.offsetHeight * 0.1) }; //y :document.body.offsetHeight*0.5 signatureBox ,this.$refs.canvasHW.offsetHeight*0.1 this.startX = obj.x; this.startY = obj.y; this.canvasTxt.beginPath();// this.points.push(obj);// } }, mouseMove // mouseMove(ev) { ev = ev || event; ev.preventDefault(); if (this.isDown) { let obj = { x: ev.offsetX, y: ev.offsetY }; this.moveY = obj.y; this.moveX = obj.x; this.canvasTxt.moveTo(this.startX, this.startY);// this.canvasTxt.lineTo(obj.x, obj.y);// this.canvasTxt.stroke();// this.startY = obj.y; this.startX = obj.x; this.points.push(obj);// } }, touchMove // touchMove(ev) { ev = ev || event; ev.preventDefault(); if (ev.touches.length == 1) { let obj = { x: ev.targetTouches[0].clientX, y: ev.targetTouches[0].clientY - (document.body.offsetHeight * 0.5 + this.$refs.canvasHW.offsetHeight * 0.1) }; this.moveY = obj.y; this.moveX = obj.x; this.canvasTxt.moveTo(this.startX, this.startY);// this.canvasTxt.lineTo(obj.x, obj.y);// this.canvasTxt.stroke();// this.startY = obj.y; this.startX = obj.x; this.points.push(obj);// } }, mouseUp // mouseUp(ev) { ev = ev || event; ev.preventDefault(); if (1) { let obj = { x: ev.offsetX, y: ev.offsetY }; this.canvasTxt.closePath();// this.points.push(obj);// this.points.push({ x: -1, y: -1 }); this.isDown = false; } }, touchEnd // touchEnd(ev) { ev = ev || event; ev.preventDefault(); if (ev.touches.length == 1) { let obj = { x: ev.targetTouches[0].clientX, y: ev.targetTouches[0].clientY - (document.body.offsetHeight * 0.5 + this.$refs.canvasHW.offsetHeight * 0.1) }; this.canvasTxt.closePath();// this.points.push(obj);// this.points.push({ x: -1, y: -1 });// } }, 다시 쓴다자신 이 오 자 를 쓴 것 을 발견 하고 화판 을 지우 고 다시 썼 다. // overwrite() { this.canvasTxt.clearRect( 0, 0, this.$refs.canvasF.width, this.$refs.canvasF.height ); this.points = []; this.isDraw = false; // }, 사용 한 data data() { return { points: [], canvasTxt: null, startX: 0, startY: 0, moveY: 0, moveX: 0, endY: 0, endX: 0, w: null, h: null, isDown: false, color: "#000", linewidth: 3, isDraw: false // }; }, 이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다. 이 내용에 흥미가 있습니까? 현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다: Fastapi websocket 및 vue 3(Composition API) 1부: FastAPI virtualenv 만들기(선택 사항) FastAPI 및 필요한 모든 것을 다음과 같이 설치하십시오. 생성main.py 파일 및 실행 - 브라우저에서 이 링크 열기http://127.0.0.1:... 텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오. CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다. ajax 사용자 이름과 비밀 번 호 를 검증 하 는 인 스 턴 스 코드 C\#문자열 과 유 니 코드 가 서로 실전 사례 를 변환 합 니 다. 좋은 웹페이지 즐겨찾기 개발자 우수 사이트 수집 개발자가 알아야 할 필수 사이트 100선 추천 우리는 당신을 위해 100개의 자주 사용하는 개발자 학습 사이트를 정리했습니다