/*! For license information please see 9950.ad9fb983.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["9950"],{20558:function(n,s,t){"use strict";t.r(s);var a=t("80681");let e=["innerHTML"];s.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

Signature

\n

Intro

\n

Component for signature scene, based on Canvas. Please upgrade vant to >= v4.3.0 before using this component.

\n

Install

\n

Register component globally via app.use, refer to Component Registration for more registration ways.

\n
import { createApp } from 'vue';\nimport { Signature } from 'vant';\n\nconst app = createApp();\napp.use(Signature);\n
\n

Usage

\n

Basic Usage

\n

When the confirm button is clicked, the component will emit the submit event. The first parameter of the event is data, which contains the following fields:

\n\n
<van-signature @submit="onSubmit" @clear="onClear" />\n<van-image v-if="image" :src="image" />\n
\n
import { ref } from 'vue';\nimport { showToast } from 'vant';\n\nexport default {\n  setup() {\n    const image = ref('');\n    const onSubmit = (data) => {\n      image.value = data.image;\n    };\n    const onClear = () => showToast('clear');\n\n    return {\n      image,\n      onSubmit,\n      onClear,\n    };\n  },\n};\n
\n

Pen Color

\n

Use pen-color prop to set the color of the brush stroke.

\n
<van-signature pen-color="#ff0000" @submit="onSubmit" @clear="onClear" />\n
\n

Line Width

\n

Use line-width prop to set the width of the line.

\n
<van-signature :line-width="6" @submit="onSubmit" @clear="onClear" />\n
\n

Background Color

\n

Use background-color prop to set the color of the background.

\n
<van-signature background-color="#eee" @submit="onSubmit" @clear="onClear" />\n
\n

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ParameterDescriptionTypeDefault
typeExport image typestringpng
pen-colorColor of the brush stroke, default is blackstring#000
line-widthWidth of the linenumber3
background-colorBackground colorstring-
tipsText that appears when Canvas is not supportedstring-
clear-button-textClear button textstringClear
confirm-button-textConfirm button textstringConfirm
\n

Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Event NameDescriptionCallback Parameters
startEmitted when signing starts-
endEmitted when signing ends-
signingEmitted when signingevent: TouchEvent
submitEmitted when clicking the confirm buttondata: { image: string; canvas: HTMLCanvasElement }
clearEmitted when clicking the cancel button-
\n

Methods

\n

Use ref to get Signature instance and call instance methods.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionAttributeReturn value
resize v4.7.3Resize Signature when container element resized or visibility changed--
clear v4.8.6Can be called to clear the signature--
submit v4.8.6Trigger the submit event, which is equivalent to clicking the confirm button.--
\n

Types

\n

The component exports the following type definitions:

\n
import type { SignatureProps, SignatureInstance } from 'vant';\n
\n

SignatureInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { SignatureInstance } from 'vant';\n\nconst signatureRef = ref<SignatureInstance>();\n\nsignatureRef.value?.resize();\n
\n

Theming

\n

CSS Variables

\n

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDefault ValueDescription
--van-signature-paddingvar(--van-padding-xs)-
--van-signature-content-height200pxHeight of the canvas
--van-signature-content-backgroundvar(--van-background-2)Background color of the canvas
--van-signature-content-border1px dotted #dadadaBorder style of the canvas
\n
'},null,8,e))}}}]);