-
-
Save CodeOcee/08392c6e1d34790c5c9dc270e5f83b83 to your computer and use it in GitHub Desktop.
A VueJS Signature canvas field, using szimek/signature_pad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<canvas class="signature"></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() { | |
let canvas = document.querySelector('canvas'); | |
this.pad = new SignaturePad(canvas, { | |
onEnd: () => { | |
this.$emit('input', this.pad.toDataURL()); | |
} | |
}); | |
}, | |
methods: { | |
clear() { | |
this.pad.clear(); | |
this.$emit('input', this.pad.toDataURL()); | |
}, | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment