心有法竹
2022-12-09 13:43:39
我想使用 2 個(gè)插件,objection-password和objection-paginator,但所有插件都需要擴(kuò)展一些基類,即用戶類。如何在 objectionjs 中擴(kuò)展 2 個(gè)類?我的代碼const Password = require('objection-password')()const Paginator = require('objection-paginator')const { Model } = require('objection')// Users class also must extends Passoword to use the methodclass Users extends Paginator(Model) { static get tableName () { return 'users' }}module.exports = Users
1 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
為了使用多個(gè)插件,您需要使用反對(duì)包中的 mixins
使用多個(gè)插件后,您的代碼應(yīng)該如下所示。
const Password = require('objection-password')()
const Paginator = require('objection-paginator')
const { mixin, Model } = require('objection')
// Users class also must extends Passoword to use the method
class Users extends mixin(Model, [
? ? Password,
? ? Paginator
]) {
? static get tableName () {
? ? return 'users'
? }
}
module.exports = Users
添加回答
舉報(bào)
0/150
提交
取消