欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

VUE使用canvas實(shí)現(xiàn)簽名組件

 更新時(shí)間:2022年07月13日 11:01:06   作者:#麻辣小龍蝦#  
這篇文章主要為大家詳細(xì)介紹了VUE使用canvas實(shí)現(xiàn)簽名組件,兼容PC移動(dòng)端,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了VUE使用canvas實(shí)現(xiàn)簽名組件的具體代碼,供大家參考,具體內(nèi)容如下

效果如下:

<template>
? <div class="sign">
? ? <div class="content">
? ? ? <canvas id="canvas" :width="width" :height="height"/>
? ? </div>
? ? <div class="btn">
? ? ? <button @click="clearCanvas()">清除</button>
? ? ? <button @click="save()">保存</button>
? ? </div>
? </div>
</template>
?
<script>
export default {
? name: 'App',
? data () {
? ? return {
? ? };
? },
? props: {
? ? // 畫(huà)布寬度
? ? width: {
? ? ? type: Number,
? ? ? default: window.innerWidth
? ? },
? ? // 畫(huà)布高度
? ? height: {
? ? ? type: Number,
? ? ? default: 500
? ? },
? ? // 筆觸半徑
? ? radius: {
? ? ? type: Number,
? ? ? default: 10
? ? },
? ? // 筆觸顏色
? ? color: {
? ? ? type: String,
? ? ? default: '#000'
? ? },
? ? // 畫(huà)布填充背景
? ? fillStyle: {
? ? ? type: String,
? ? ? default: '#ccc'
? ? }
? },
? created () {
? },
? mounted () {
? ? this.int();
? },
? methods: {
? ? // 繪制涂擦效果圓形
? ? // @param { integer } 圓心的x坐標(biāo)
? ? // @param { integer } 圓心的y坐標(biāo)
? ? // @param { integer } 圓心半徑
? ? // @param { string } 填充的顏色
? ? fillCircle (ctx, x, y, radius, fillColor) {
? ? ? ctx.fillStyle = fillColor || this.color;
? ? ? ctx.beginPath();
? ? ? ctx.moveTo(x, y);
? ? ? ctx.arc(x, y, radius, 0, Math.PI * 2, false); // 標(biāo)準(zhǔn)畫(huà)圓
? ? ? ctx.fill();
? ? },
? ? // 保存圖片
? ? save (name = '簽名圖片') {
? ? ? let imgBase64 = this.canvas.toDataURL('image/png'); // 獲取截圖base64, 1表示質(zhì)量(無(wú)損壓縮)
? ? ? let a = document.createElement('a');
? ? ? a.download = name + '.png'; // 必須要設(shè)置download屬性才能夠直接下載base64圖片
? ? ? a.href = imgBase64;
? ? ? a.click(); // 觸發(fā)點(diǎn)擊,起到下載效果
? ? },
? ? // 清除畫(huà)布
? ? clearCanvas () {
? ? ? let canvas = this.canvas;
? ? ? canvas.getContext('2d').fillStyle = this.fillStyle;
? ? ? canvas.getContext('2d').fillRect(0, 0, this.width, this.height);
? ? },
? ? // 數(shù)據(jù)初始化
? ? int () {
? ? ? this.canvas = document.querySelector('#canvas');
? ? ? let ctx = this.canvas.getContext('2d');
? ? ? let move = false; // 按下標(biāo)識(shí)
? ? ? ctx.fillStyle = this.fillStyle;
? ? ? ctx.fillRect(0, 0, this.width, this.height);
? ? ? // 事件兼容PC 移動(dòng)端
? ? ? let eventStart = 'ontouchstart' in document ? 'touchstart' : 'mousedown';
? ? ? let eventMove = 'ontouchmove' in document ? 'touchmove' : 'mousemove';
? ? ? let eventEnd = 'ontouchend' in document ? 'touchend' : 'mouseup';
? ? ? this.canvas.addEventListener(eventStart, (e) => {
? ? ? ? console.log(e);
? ? ? ? let sx = e.touches ? e.touches[0].pageX : e.pageX;
? ? ? ? let sy = e.touches ? e.touches[0].pageY : e.pageY;
? ? ? ? move = true;
? ? ? ? this.fillCircle(ctx, sx, sy, this.radius);
? ? ? }, false);
? ? ? this.canvas.addEventListener(eventMove, (e) => {
? ? ? ? let sx = e.touches ? e.touches[0].pageX : e.pageX;
? ? ? ? let sy = e.touches ? e.touches[0].pageY : e.pageY;
? ? ? ? move && this.fillCircle(ctx, sx, sy, this.radius);
? ? ? }, false);
? ? ? this.canvas.addEventListener(eventEnd, (e) => {
? ? ? ? move = false;
? ? ? }, false);
? ? }
? }
};
</script>
<style lang="less" scoped>
.sign{
? .btn {
? ? padding:10px;
? ? button {
? ? ? height: 50px;
? ? ? width:100%;
? ? ? margin-bottom:10px;
? ? ? font-size: 20px;
? ? }
? }
}
</style>

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

相關(guān)文章

  • vue實(shí)現(xiàn)動(dòng)態(tài)進(jìn)度條效果

    vue實(shí)現(xiàn)動(dòng)態(tài)進(jìn)度條效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)動(dòng)態(tài)進(jìn)度條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue3?setup添加name的方法步驟

    Vue3?setup添加name的方法步驟

    如果你在 vue3 開(kāi)發(fā)中使用了語(yǔ)法的話(huà),對(duì)于組件的name屬性,需要做一番額外的處理,下面這篇文章主要給大家介紹了關(guān)于Vue3?setup添加name的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • 詳解如何在vue中封裝axios請(qǐng)求并集中管理

    詳解如何在vue中封裝axios請(qǐng)求并集中管理

    這篇文章主要為大家詳細(xì)介紹了如何在vue中封裝axios請(qǐng)求并集中管理,w文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,有需要的小伙伴可以了解下
    2023-10-10
  • vue axios用法教程詳解

    vue axios用法教程詳解

    axios是vue-resource后出現(xiàn)的Vue請(qǐng)求數(shù)據(jù)的插件。下面我們通過(guò)本文給大家介紹vue axios用法教程詳解,感興趣的朋友一起看看吧
    2017-07-07
  • 快速將Vue項(xiàng)目升級(jí)到webpack3的方法步驟

    快速將Vue項(xiàng)目升級(jí)到webpack3的方法步驟

    這篇文章主要給大家介紹了關(guān)于如何快速將Vue項(xiàng)目升級(jí)到webpack3的方法步驟文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-09-09
  • vue組件化中slot的基本使用方法

    vue組件化中slot的基本使用方法

    這篇文章主要給大家介紹了關(guān)于vue組件化中slot的基本使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 淺談mvvm-simple雙向綁定簡(jiǎn)單實(shí)現(xiàn)

    淺談mvvm-simple雙向綁定簡(jiǎn)單實(shí)現(xiàn)

    本篇文章主要介紹了淺談mvvm-simple雙向綁定簡(jiǎn)單實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • 基于Vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)表單的校驗(yàn)功能(根據(jù)條件動(dòng)態(tài)切換校驗(yàn)格式)

    基于Vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)表單的校驗(yàn)功能(根據(jù)條件動(dòng)態(tài)切換校驗(yàn)格式)

    這篇文章主要介紹了Vue+elementUI的動(dòng)態(tài)表單的校驗(yàn)(根據(jù)條件動(dòng)態(tài)切換校驗(yàn)格式),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04
  • VuePress 側(cè)邊欄的具體使用

    VuePress 側(cè)邊欄的具體使用

    本文主要介紹了VuePress 側(cè)邊欄的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • vue 動(dòng)態(tài)創(chuàng)建組件的兩種方法

    vue 動(dòng)態(tài)創(chuàng)建組件的兩種方法

    這篇文章主要介紹了vue 動(dòng)態(tài)創(chuàng)建組件的兩種方法,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2020-12-12

最新評(píng)論