-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
26 lines (26 loc) · 901 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let vNoScroll = {}
vNoScroll.install = function (Vue) {
Vue.directive('no-scroll', function (el, binding) {
let show = binding.value.showLayer,
parentEl = binding.value.parentEl;
if (show) {
el.addEventListener("touchmove", function (event) {
event.preventDefault();
});
if (parentEl) {
// 按需加载引入
// default 输出接口,可以用参数直接获得,使用具名输入的形式
import('better-scroll').then(({
default: BScroll
}) => {
new BScroll(document.getElementById(parentEl));
})
}
} else {
el.removeEventListener("touchmove", function (event) {
event.preventDefault();
});
}
})
}
export default vNoScroll;