美文网首页
vue 全局挂在自定义指令

vue 全局挂在自定义指令

作者: PharkiLL | 来源:发表于2021-11-08 11:54 被阅读0次
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)

相关文章

网友评论

      本文标题:vue 全局挂在自定义指令

      本文链接:https://www.haomeiwen.com/subject/jzeuzltx.html