0
点赞
收藏
分享

微信扫一扫

Vue 全局变量挂载

穿裙子的程序员 2022-01-17 阅读 56

1. vue2

Vue.prototype.$lm = {}

2. vue3

const app = Vue.createApp({})
app.config.globalProperties.$lm = {}

3. 生命类型

我们需要声明一下:

新建一个 xxx.d.ts 文件,例如 我这边创建一个 vue.d.ts

export { }
declare module '@vue/runtime-core' {
    interface ComponentCustomProperties {
        $axios: any
    }
}

其中 export{} 必须保留。

ok,现在就可以通过this. 来访问 $axios 对象了。

项目实例代码:

 

 

举报

相关推荐

0 条评论