5.6.3 • Published 5 months ago

@cimom/vben-constants v5.6.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@cimom/vben-constants

用于多个 app 公用的常量,继承了 @cimom/vben-core-shared/constants 的所有能力。业务上有通用常量可以放在这里。

安装

# 进入目标应用目录,例如 apps/xxxx-app
# cd apps/xxxx-app
pnpm add @cimom/vben-constants

使用

import { LOGIN_PATH, SUPPORT_LANGUAGES } from '@cimom/vben-constants';

可用常量

路由相关常量

// 登录页面路径
import { LOGIN_PATH } from '@cimom/vben-constants';

// 使用示例
const router = createRouter({
  routes: [
    {
      path: LOGIN_PATH,
      component: () => import('./views/login/index.vue'),
    },
  ],
});

国际化相关常量

// 支持的语言列表
import { SUPPORT_LANGUAGES, type LanguageOption } from '@cimom/vben-constants';

// 使用示例
const languages = SUPPORT_LANGUAGES;
// 输出:
// [
//   { label: '简体中文', value: 'zh-CN' },
//   { label: 'English', value: 'en-US' }
// ]

// 获取当前语言
const currentLanguage = SUPPORT_LANGUAGES.find(
  (lang) => lang.value === 'zh-CN',
);
// 输出: { label: '简体中文', value: 'zh-CN' }

扩展常量

如果需要添加新的常量,可以在项目中创建新的常量文件,然后导出:

// 在项目中创建 src/constants/app.ts
export const APP_NAME = 'Vben Admin';
export const APP_VERSION = '1.0.0';

// 在项目中使用
import { APP_NAME, APP_VERSION } from './constants/app';
import { LOGIN_PATH } from '@cimom/vben-constants';

console.log(`${APP_NAME} v${APP_VERSION}`);
console.log(`Login path: ${LOGIN_PATH}`);

继承的常量

该包继承了 @cimom/vben-core-shared/constants 中定义的所有常量,可以直接从 @cimom/vben-constants 中导入使用。

类型定义

// 语言选项类型定义
export interface LanguageOption {
  label: string;
  value: 'en-US' | 'zh-CN';
}
5.6.3

5 months ago

5.6.1

5 months ago

5.6.0

5 months ago

5.5.12

5 months ago

5.5.9

5 months ago