vue3 + ts 声明全局属性,app.config.globalProperties的使用
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue

·
1. 增加属性
import { App } from "vue";
const settingSystemAttrs = {
install(app: App<Element>) {
app.config.globalProperties.$systemName = "xxxxxxxxx";
},
};
export { settingSystemAttrs };
2. 增加声明ts文件
export {}; // 这个必须加上,原因如下图
declare module "vue" {
interface ComponentCustomProperties {
$systemName: string;
}
}
上面图片出处:https://cn.vuejs.org/guide/typescript/options-api.html#augmenting-global-properties
3. 在tsconfig.json文件中声明
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "声明declare文件的路径.ts"],




vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:3 天前 )
9e887079
[skip ci] 10 个月前
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
更多推荐
所有评论(0)