Constant
Modules can individually provide their own Constant
Define Constant
Taking the module a-demo
as an example, define the Constant
of the module:
src/suite/a-demo/modules/a-demo/src/config/constants.ts
typescript
export const constants = {
gender: {
male: 1,
female: 2,
},
};
- Just define the required constants directly, and the system will automatically extract the type information of constants
Use Constant
The Constant
of the module can be obtained through the Scope
instance
typescript
export class TestA {
protected async __init__() {
const male = this.scope.constant.gender.male;
const female = this.scope.constant.gender.female;
console.log(male, female);
}
}
- Gif Demonstration
Use Constant cross-module
typescript
import type { ScopeModuleADemo } from 'zova-module-a-demo';
export class TestA {
@UseScope('a-demo')
scopeModuleADemo: ScopeModuleADemo;
protected async __init__() {
const male = this.scopeModuleADemo.constant.gender.male;
const female = this.scopeModuleADemo.constant.gender.female;
console.log(male, female);
}
}