1.1.5 • Published 5 years ago

egg-helper v1.1.5

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

egg-helper

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-helper --save

Usage

// {app_root}/config/plugin.js
exports.helper = {
  enable: true,
  package: 'egg-helper',
};

Configuration

// {app_root}/config/config.default.js
exports.helper = {

};

see config/config.default.js for more detail.

Example

Divide egg's app/extend/help.js method into different files for easy maintenance

Add the util1.js file to the app/helper folder

// app/helper/util.js
module.exports = app => {
  return {
    foo() {
      // app is Application Object
      console.log(app);
      return 'hello helper';
    },
  };
};

aslo you can use multiple levels of directories like app/helper/util/util1.js

// app/helper/util/util1.js
module.exports = app => {
  return {
    foo1() {
      // app is Application Object
      console.log(app);
      return 'hello helper';
    },
  };
};

in Controller

DemoController extends Controller{
  async index(){
    this.ctx.helper.util.foo(); // You can access your method through the following path
    this.ctx.helper.util.util1.foo1();// If you use a multi-level directory,You can access your method through the following path
  }
}

Questions & Suggestions

Please open an issue here.

License

MIT

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago