1.1.5 • Published 5 years ago
egg-helper v1.1.5
egg-helper
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.