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 对象了。
项目实例代码: