cleave.ts 587 B

1234567891011121314151617181920
  1. import Cleave from 'cleave.js'
  2. /** Intégration de la librairie cleave.js
  3. * @see https://github.com/nosir/cleave.js
  4. * @see https://github.com/nosir/cleave.js/blob/master/doc/vue.md
  5. */
  6. export default defineNuxtPlugin((nuxtApp) => {
  7. nuxtApp.vueApp.directive('cleave', {
  8. mounted: (el, binding) => {
  9. el.cleave = new Cleave(el, binding.value ?? {})
  10. },
  11. updated: (el) => {
  12. const event = new Event('input', { bubbles: true })
  13. setTimeout(function () {
  14. el.value = el.cleave.properties.result
  15. el.dispatchEvent(event)
  16. }, 100)
  17. },
  18. })
  19. })