亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于Vue實(shí)現(xiàn)手勢(shì)簽名

 更新時(shí)間:2022年08月29日 16:48:27   作者:qq_38192105  
這篇文章主要為大家詳細(xì)介紹了基于Vue實(shí)現(xiàn)手勢(shì)簽名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了基于Vue實(shí)現(xiàn)手勢(shì)簽名的具體代碼,供大家參考,具體內(nèi)容如下

廢話不多說,直接上效果圖&源碼

代碼如下

1. template

<template>
? <main class="hand-sign-page">
? ? <header class="sign-head">請(qǐng)?jiān)谙路絽^(qū)域內(nèi)簽名</header>
? ? <div id="signContain" :style="{'--back': background}"></div>
? ? <footer class="sign-foot">
? ? ? <button @click="clearCanvas">清除</button>
? ? ? <button @click="saveCanvas">保存</button>
? ? </footer>
? ? <img v-show="vaildSign" class="sign-img" :src="vaildSign" alt=" "/>
? </main>
</template>

2. js

<script>
? export default {
? ? name: "hand-sign",
? ? data() {
? ? ? return {
? ? ? ? domEl: null,//繪制canvas的父級(jí)div
? ? ? ? canvas: null,//畫布
? ? ? ? cxt: null,//繪畫環(huán)境
? ? ? ? linewidth:1,//線條粗細(xì),選填
? ? ? ? color:"black",//線條顏色,選填
? ? ? ? background:"aliceblue",//線條背景,選填
? ? ? ? vaildSign: null
? ? ? }
? ? },
? ??
? ? mounted() {
? ? ? this.initCanvas();
? ? },

? ? methods: {
? ? ? initCanvas() {
? ? ? ? this.domEl = document.getElementById("signContain");
? ? ? ? this.canvas = document.createElement("canvas");
? ? ? ? this.domEl.appendChild(this.canvas);
? ? ? ? this.cxt = this.canvas.getContext("2d");
? ? ? ? this.canvas.width = this.domEl.clientWidth;
? ? ? ? this.canvas.height = this.domEl.clientHeight;
? ? ? ? this.cxt.fillStyle = this.background;
? ? ? ? this.cxt.fillRect(0, 0, this.canvas.width, this.canvas.height);
? ? ? ? this.cxt.strokeStyle = this.color;
? ? ? ? this.cxt.lineWidth = this.linewidth;
? ? ? ? //this.cxt.lineCap = "round";
? ? ? ? this.clearCanvas();//先清理下

? ? ? ? //開始繪制
? ? ? ? this.canvas.addEventListener("touchstart", (e) => {
? ? ? ? ? this.cxt.beginPath();
? ? ? ? ? this.cxt.moveTo(e.changedTouches[0].pageX - e.target.offsetLeft, e.changedTouches[0].pageY - e.target.offsetTop);
? ? ? ? }, false);

? ? ? ? //繪制中
? ? ? ? this.canvas.addEventListener("touchmove", (e)=> {
? ? ? ? ? this.cxt.lineTo(e.changedTouches[0].pageX - e.target.offsetLeft, e.changedTouches[0].pageY - e.target.offsetTop);
? ? ? ? ? this.cxt.stroke();
? ? ? ? }, false);
? ? ? ??
? ? ? ? //結(jié)束繪制
? ? ? ? this.canvas.addEventListener("touchend", (e)=> {
? ? ? ? ? this.cxt.closePath();
? ? ? ? }, false);
? ? ? },

? ? ? //清除畫布
? ? ? clearCanvas() {
? ? ? ? this.cxt.clearRect(0, 0, this.canvas.width, this.canvas.height);
? ? ? },

? ? ? //保存畫布
? ? ? saveCanvas() {
? ? ? ? console.log(this.blankCanvas());//檢查畫布是否為空白
? ? ? ? if(this.blankCanvas()) {
? ? ? ? ? window.alert('請(qǐng)簽名');
? ? ? ? }else {
? ? ? ? ? this.vaildSign = this.canvas.toDataURL();
? ? ? ? }
? ? ? },

? ? ? //canvas非空驗(yàn)證
? ? ? blankCanvas() {
? ? ? ? let blank = document.createElement('canvas');//系統(tǒng)獲取一個(gè)空canvas對(duì)象
? ? ? ? blank.width = this.canvas.width;
? ? ? ? blank.height = this.canvas.height;
? ? ? ? return this.canvas.toDataURL() == blank.toDataURL();//比較值相等則為空
? ? ? },

? ? }
? }
</script>

3. css

<style lang="less" scoped>
? .hw(@h, @w: @h) {
? ? height: @h;
? ? width: @w
? }

? .hand-sign-page{
? ? background-color: #fff;
? ? .sign-head {
? ? ? text-align: center;
? ? ? padding: 10px;
? ? ? border-bottom: 1px solid #ebebeb;
? ? ? color: #666;
? ? ? font-size: 14px;
? ? }

? ? #signContain {
? ? ? .hw(400px, 100%);
? ? ? background-color: var(--back);
? ? }

? ? .sign-foot{
? ? ? display: flex;
? ? ? justify-content: center;
? ? ? margin: 15px;

? ? ? button {
? ? ? ? margin: 0 15px;
? ? ? ? padding: 10px 20px;
? ? ? ? background-color: #ddd;
? ? ? ? border-radius: 5px;

? ? ? ? &:active {
? ? ? ? ? background-color: #efefef;
? ? ? ? }
? ? ? }
? ? }

? ? .sign-img {
? ? ? .hw(100px, 200px);
? ? ? display: block;
? ? ? margin: 10px auto;
? ? }
? }

</style>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue給?elementUI?中的?this.$confirm、this.$alert、?this.$prompt添加按鈕加載效果

    Vue給?elementUI?中的?this.$confirm、this.$alert、?this.$promp

    這篇文章主要介紹了Vue給?elementUI?中的?this.$confirm、this.$alert、?this.$prompt添加按鈕的加載效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • Vue開發(fā)Html5微信公眾號(hào)的步驟

    Vue開發(fā)Html5微信公眾號(hào)的步驟

    這篇文章主要介紹了Vue開發(fā)Html5微信公眾號(hào)的步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-04-04
  • vue2與vue3雙向數(shù)據(jù)綁定的區(qū)別說明

    vue2與vue3雙向數(shù)據(jù)綁定的區(qū)別說明

    這篇文章主要介紹了vue2與vue3雙向數(shù)據(jù)綁定的區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 在vue中安裝使用vux的教程詳解

    在vue中安裝使用vux的教程詳解

    這篇文章主要介紹了在vue中安裝使用vux的教程,本文給大家記錄了vuex的安裝使用過程,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2018-09-09
  • vue?tree封裝一個(gè)可選的樹組件方式

    vue?tree封裝一個(gè)可選的樹組件方式

    這篇文章主要介紹了vue?tree封裝一個(gè)可選的樹組件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Vue 2.x教程之基礎(chǔ)API

    Vue 2.x教程之基礎(chǔ)API

    這篇文章主要介紹了Vue 2.x基礎(chǔ)API的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • vue-router解決相同路徑跳轉(zhuǎn)報(bào)錯(cuò)的問題

    vue-router解決相同路徑跳轉(zhuǎn)報(bào)錯(cuò)的問題

    這篇文章主要介紹了vue-router解決相同路徑跳轉(zhuǎn)報(bào)錯(cuò)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue實(shí)現(xiàn)購物車的小練習(xí)

    vue實(shí)現(xiàn)購物車的小練習(xí)

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)購物車的小練習(xí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • vue?this.$router.go(-1);返回時(shí)如何帶參數(shù)

    vue?this.$router.go(-1);返回時(shí)如何帶參數(shù)

    這篇文章主要介紹了vue?this.$router.go(-1);返回時(shí)如何帶參數(shù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Vue首屏白屏問題的原因和解決方法講解

    Vue首屏白屏問題的原因和解決方法講解

    這篇文章主要介紹了Vue首屏白屏問題的原因和解決方法講解,Vue首屏白屏問題是指在頁面初次加載時(shí),部分或全部內(nèi)容無法正常顯示,出現(xiàn)空白的情況。其原因可能是因?yàn)轫撁驿秩舅俣冗^慢,或者是因?yàn)榫W(wǎng)絡(luò)請(qǐng)求等問題導(dǎo)致數(shù)據(jù)無法及時(shí)加載
    2023-05-05

最新評(píng)論