Similar to the backend Config, EggBornJS also implements the frontend Config at the module level

  1. Module can specify its own configuration
  2. The configuration at project level can override the one at module level

Definition of Config

src/suite-vendor/test-party/modules/test-party/front/src/config/config.js

  1. 1export default {
  2. 2 message: 'Hello World',
  3. 3 markCount: 2,
  4. 4};

Usage of Config

Same Module

src/suite-vendor/test-party/modules/test-party/front/src/kitchen-sink/pages/guide.vue

  1. 1onPerformClick4() {
  2. 2 const params = {
  3. 3 message: this.$config.message,
  4. 4 markCount: this.$config.markCount,
  5. 5 };
  6. 6 return this.$api.post('kitchen-sink/guide/echo4', params).then(data => {
  7. 7 this.message4 = data;
  8. 8 });
  9. 9},

Across Module

If used across modules, the way is as follows:

  1. 1this.$meta.module.use('test-party', module => {
  2. 2 const message = this.$meta.config.modules['test-party'].message;
  3. 3});
Name Description
$meta.module.use The frontend of a module is usually loaded asynchronously, so before using the module’s Config, you need to ensure that the module has been loaded
$meta.config.modules[moduleName] Get the Config of the specified module

Override Config

Also can use project level config to override module level config

src/front/config/config.{scene}.js

  1. 1export default{
  2. 2 modules: {
  3. 3 'test-party': {
  4. 4 message: 'Hello World!',
  5. 5 markCount: 3,
  6. 6 },
  7. 7 },
  8. 8};