Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vue 3.x compatible code #646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions doc/vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ While this package does not have an official support for use in VueJs. This can

## To use globally

### Vue 2.x

```js
import Vue from 'vue'
import Cleave from 'cleave.js';
Expand All @@ -22,9 +24,30 @@ Vue.directive('cleave', {
}
})
```
### Vue 3.x

```js
import Vue from 'vue'
import Cleave from 'cleave.js';

Vue.directive('cleave', {
mounted: (el, binding) => {
el.cleave = new Cleave(el, binding.value || {})
},
updated: (el) => {
const event = new Event('input', {bubbles: true});
setTimeout(function () {
el.value = el.cleave.properties.result
el.dispatchEvent(event)
}, 100);
}
})
```

## To use as a local local directive

### Vue 2.x

```js
import Cleave from 'cleave.js';
export default {
Expand All @@ -48,6 +71,32 @@ export default {
}
```

### Vue 3.x


```js
import Cleave from 'cleave.js';
export default {

...
directives: {
mounted: {
inserted: (el, binding) => {
el.cleave = new Cleave(el, binding.value || {})
},
updated: (el) => {
const event = new Event('input', {bubbles: true});
setTimeout(function () {
el.value = el.cleave.properties.result
el.dispatchEvent(event)
}, 100);
}
}
}
...
}
```

And use it in your HTML like

```html
Expand Down