1.1.1 • Published 4 months ago

koatty_views v1.1.1

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
4 months ago

koatty_views

Template rendering middleware for Koatty.

安装


npm i koatty_views

使用


Koatty

1、项目中增加middleware

koatty middleware views;

2、修改 middleware/ViewsMiddleware.ts:

import { Middleware, IMiddleware } from 'koatty';
import { Views } from 'koatty_view';
import { App } from '../App';

@Middleware()
export class ViewMiddleware implements IMiddleware {
  run(options: any, app: App) {
    return Views(options, app);
  }
}

3、项目middleware配置 config/middleware.ts:

...
// 
ViewMiddleware: {
    root: `${process.env.ROOT_PATH}/view`, // 模板目录
    opts: {
        autoRender: false,
        extension: 'html',
        map: {
            html: "ejs",
        },
        options: {
            cache: false, // 开发模式下修改为false, 生产环境请修改为true
        }
    }
},
...

4、 模板赋值:

...
// IndexController
/**
 * index 接口
 *
 * @returns
 * @memberof DefaultController
 */
@GetMapping('')
index(): Promise<any> {
    this.ctx.state = { title: 'my title', author: 'queckezz' };
    return this.ctx.render('index.html');
}
...
1.1.1

4 months ago

1.1.0

4 months ago

1.0.9

9 months ago

1.0.8

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago