vue 全局挂在自定义指令
2021-11-08 本文已影响0人
PharkiLL
directivesTool.js
import Vue from "vue";
// 防抖
const antiShake = Vue.directive("antiShake", {
bind(el,binding) {
el.addEventListener("click", () => {
console.log('自定义点击事件');
})
}
})
const directives = [
antiShake
]
export default {
install(Vue) {
// directives.map(item => item.install(app))
for(let key in directives) {
Vue.directive(key, directives[key])
}
}
}
mani.js 全局挂载
// 挂载自定义指令
import directive from '@/utils/directivesTool.js'
Vue.use(directive)