Skip to content

Commit 739de11

Browse files
laineusrigor789
andauthored
feat: add support for Vue 3 (#371)
* vue3 * Update src/index.js Co-authored-by: Igor Randjelovic <[email protected]> * Update src/index.js Co-authored-by: Igor Randjelovic <[email protected]> Co-authored-by: Igor Randjelovic <[email protected]>
1 parent 4c054d5 commit 739de11

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/directive.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function handleClick(e) {
5050
scrollTo(ctx.value.el || ctx.value.element, ctx.value)
5151
}
5252

53-
export default {
53+
const directiveHooks = {
5454
bind(el, binding) {
5555
getBinding(el).binding = binding
5656
_.on(el, 'click', handleClick)
@@ -61,7 +61,16 @@ export default {
6161
},
6262
update(el, binding) {
6363
getBinding(el).binding = binding
64-
},
64+
}
65+
}
66+
67+
export default {
68+
bind: directiveHooks.bind,
69+
unbind: directiveHooks.unbind,
70+
update: directiveHooks.update,
71+
beforeMount: directiveHooks.bind,
72+
unmounted: directiveHooks.unbind,
73+
updated: directiveHooks.update,
6574
scrollTo,
6675
bindings,
6776
}

src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { setDefaults, scroller } from './scrollTo'
44
const install = function(Vue, options) {
55
if (options) setDefaults(options)
66
Vue.directive('scroll-to', VueScrollTo)
7-
Vue.prototype.$scrollTo = VueScrollTo.scrollTo
7+
const properties = Vue.config.globalProperties || Vue.prototype
8+
properties.$scrollTo = VueScrollTo.scrollTo
89
}
910

1011
if (typeof window !== 'undefined' && window.Vue) {
1112
window.VueScrollTo = VueScrollTo
1213
window.VueScrollTo.setDefaults = setDefaults
1314
window.VueScrollTo.scroller = scroller
14-
window.Vue.use(install)
15+
if (window.Vue.use) window.Vue.use(install)
1516
}
1617

1718
VueScrollTo.install = install

0 commit comments

Comments
 (0)