Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Last active December 28, 2023 20:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stevebauman/cf41218606bb753bfb2e2fb788967828 to your computer and use it in GitHub Desktop.
Save stevebauman/cf41218606bb753bfb2e2fb788967828 to your computer and use it in GitHub Desktop.
A VueJS Signature canvas field, using szimek/signature_pad
<template>
<div>
<canvas ref="canvas"></canvas>
<div class="clearfix"></div>
<div class="btn-group">
<button @click="clear" type="button" class="btn btn-default">
<i class="fa fa-times"></i>
Clear Signature
</button>
</div>
</div>
</template>
<style>
.signature {
border: 2px solid #cbc9c6;
border-radius: 5px;
}
</style>
<script>
import SignaturePad from 'signature_pad';
export default {
props: {
value: String,
},
data() {
return {
pad: null,
};
},
mounted() {
this.pad = new SignaturePad(this.$refs.canvas, {
onEnd: () => {
this.$emit('input', this.pad.toDataURL());
}
});
},
methods: {
clear() {
this.pad.clear();
this.$emit('input', this.pad.toDataURL());
},
}
}
</script>
@stevebauman
Copy link
Author

Awesome, thanks for sharing @agm1984! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment