vue全局注册


方法一:全局注册(注册全局方法)

创建global.js

export default {
    install (Vue){
        Vue.prototype.XXX = ()=> {
        }
        ...
    }
}

main里面引入:

import global from './utils/global'
Vue.use(global);

调用时候:

this.XXX()

方法二:定义单独的方法

export function fn1(){
}
export function fn2(){
}
...

在需要使用的页面引入即可。

方法三:vue 3.0的方法

export function global(){
    const str = ref("");
    const fn = () => {
        ...
    }
    
    return {
        str,
        fn
    }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM