Constant
Modules can individually provide their own Constant
Initialize code skeleton
TIP
Context Menu - [Module Path]: Zova Init/Constant
Define Constant
Taking the module demo-basic
as an example, define the Constant
of the module:
src/suite/a-demo/modules/demo-basic/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 { ScopeModuleDemoBasic } from 'zova-module-demo-basic';
export class TestA {
@UseScope()
$$scopeModuleDemoBasic: ScopeModuleDemoBasic;
protected async __init__() {
const male = this.$$scopeModuleDemoBasic.constant.gender.male;
const female = this.$$scopeModuleDemoBasic.constant.gender.female;
console.log(male, female);
}
}