Skip to content

Commit

Permalink
Fix Vue.js v2.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
M1CK431 committed Feb 18, 2022
1 parent 3c0e520 commit 7e3839c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ const $clipboard = (input) => {

export default {
install(app) {
// Vue.prototype.$clipboard = $clipboard
app.config.globalProperties.$clipboard = $clipboard
// Vue v2.x compat
const globalCtx =
app.version[0] === '3' ? app.config.globalProperties : app.prototype
globalCtx.$clipboard = $clipboard

const generateId = ((id) => () => '$' + id++)(1)
const handlers = {}
Expand All @@ -78,9 +80,7 @@ export default {
return id
}

// Vue.directive('clipboard', {
app.directive('clipboard', {
// bind(el, binding) {
beforeMount(el, binding) {
const { arg, value } = binding

Expand Down Expand Up @@ -138,6 +138,14 @@ export default {
el.removeEventListener('click', handlers[clipboardClickHandler])
removeHandler(clipboardClickHandler)
}
},

// Vue v2.x compat
get bind() {
return this.beforeMount
},
get unbind() {
return this.unmounted
}
})
}
Expand Down

0 comments on commit 7e3839c

Please sign in to comment.