Skip to content

SignaturePad ​

Canvas-based signature pad component wrapping the signature_pad library. Supports v-model binding, clear, and confirm operations.


Basic Usage ​

Draw a signature on the panel and click confirm to get the Base64 DataURL.

vue

<TSignaturePad v-model="signature" />

Custom Colors & Size ​

Customize pen color and canvas dimensions via pen-color, :width, and :height.

vue

<TSignaturePad pen-color="#0ca678" :width="300" :height="150" />
<TSignaturePad pen-color="#d63939" :width="300" :height="150" />

Disabled State ​

Set disabled to prevent drawing, useful for viewing signed signatures.

vue

<TSignaturePad disabled />

Stroke Width (Range Slider) ​

Use TSlider range mode to control both min and max line width simultaneously.

vue

<TSlider v-model="range" :min="0.5" :max="10" :step="0.5" range />
<TSignaturePad :min-width="range[0]" :max-width="range[1]" />

Undo / Redo ​

Call undo() / redo() methods via ref to revert or reapply strokes. Use hasUndo / hasRedo to control button disabled state.

vue

<TSignaturePad ref="padRef">
  <template #footer>
    <button :disabled="!padRef?.hasUndo" @click="padRef?.undo()">Undo</button>
    <button :disabled="!padRef?.hasRedo" @click="padRef?.redo()">Redo</button>
    <button @click="padRef?.clear()">Clear</button>
  </template>
</TSignaturePad>

Custom Layout ​

Use :layout prop to control the action buttons in the footer. Default is ['ok','res'] (confirm + reset). Optional: 'undo', 'redo', 'width' (stroke width slider).

vue

<TSignaturePad :layout="['ok','res','undo','redo','width']" />

Save Format ​

Use save-format prop to control the output image format: 'png' (default), 'jpeg', or 'svg'.

vue

<TSignaturePad save-format="svg" @confirm="handleConfirm" />

Use #footer slot to customize the action button area. Combine with exposed methods (clear, undo, redo) and emits (@confirm, @end-stroke) for complete custom interaction.

vue

<TSignaturePad ref="padRef" @confirm="onConfirm">
  <template #footer>
    <TSlider v-model="range" :min="0.5" :max="6" :step="0.5" range />
    <button @click="padRef?.undo()">Undo</button>
    <button @click="padRef?.clear()">Resign</button>
  </template>
</TSignaturePad>

API ​

Props ​

PropTypeDefaultDescription
model-value / v-modelstring''Signature DataURL
widthnumber | string'100%'Canvas width (number for px, string for CSS value like '100%')
heightnumber | string200Canvas height (number for px, string for CSS value)
pen-colorstring'#000000'Pen color
background-colorstring'rgba(0,0,0,0)'Background color
min-widthnumber0.5Minimum line width
max-widthnumber2.5Maximum line width
throttlenumber16Throttle interval (ms)
disabledbooleanfalseDisable drawing
save-format'png' | 'jpeg' | 'svg''png'Output image format on confirm
confirm-textstring'确认'Confirm button text
layout('ok'|'res'|'undo'|'redo'|'width')[]['ok','res']Footer layout items

Emits ​

EventParametersDescription
update:model-valuedataURL: string | nullv-model update
confirmdataURL: stringSignature confirmed
clear—Signature cleared
end-strokeisEmpty: booleanFires after each stroke ends

Expose ​

MethodDescription
isEmpty()Whether signature is empty
toDataURL(type?, encoderOptions?)Get signature DataURL
toSVG()Get signature as SVG string
fromDataURL(dataURL)Load signature from DataURL
clear()Clear signature
undo()Undo last stroke
redo()Redo undone stroke
hasUndoWhether undo is available (reactive ref)
hasRedoWhether redo is available (reactive ref)

Slots ​

SlotDescription
footerCustom action buttons area