vue的一些扩展的方法

1,174 阅读1分钟

vue 的一些扩展的方法

扩展全局组建

const components={
    component1,
    component2,
    component3
}
for(let key in components){
    Vue.component(key,components[key])
}

扩展全局指令

Vue.directive("option", {
    inserted(dom, binding) {
        dom.addEventListener("click", (e) => {
            const node = e.target
            const x = e.pageX
            const y = e.pageY
            console.log(node, x, y)
        })
        console.log(dom, binding)
    }
})

扩展 veu 类的方法

Vue.method=function(){
    console.log("扩展了类的方法")
}

扩展 vue 原型,在 vue 组件中就可以通过 this 访问调用

Vue.proptype.$api= function1(){
        console.log("调用api")
    }