2021-10-28 22:55:51 +08:00
|
|
|
---
|
|
|
|
toc: menu
|
|
|
|
---
|
|
|
|
|
|
|
|
# Context
|
|
|
|
|
|
|
|
## ctx.db
|
|
|
|
|
2021-11-09 15:08:24 +08:00
|
|
|
##### Definition
|
|
|
|
|
|
|
|
```ts
|
|
|
|
interface Context {
|
|
|
|
db: Database;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
##### Examples
|
|
|
|
|
|
|
|
```ts
|
|
|
|
async (ctx, next) {
|
|
|
|
const User = ctx.db.getCollection('users');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-10-28 22:55:51 +08:00
|
|
|
## ctx.resourcer
|
|
|
|
|
2021-11-17 18:54:32 +08:00
|
|
|
## ctx.action <Badge>待完善</Badge>
|
2021-10-28 22:55:51 +08:00
|
|
|
|
|
|
|
## ctx.i18n
|
|
|
|
|
2021-11-09 15:08:24 +08:00
|
|
|
app.i18n 的 cloneInstance。详情见 [I18next API](https://www.i18next.com/overview/api)
|
|
|
|
|
|
|
|
##### Definition
|
|
|
|
|
|
|
|
```ts
|
|
|
|
interface Context {
|
|
|
|
i18n: I18next.I18n;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
##### Examples
|
|
|
|
|
|
|
|
```ts
|
|
|
|
async (ctx, next) {
|
|
|
|
await ctx.i18n.changeLanguage('zh-CN');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-10-28 22:55:51 +08:00
|
|
|
## ctx.t()
|
|
|
|
|