在商店里,我有两个相关的模型:Company和User
用户
import { Model } from '@vuex-orm/core';
import { Company } from './models';
export class User extends Model {
static entity = 'users';
static fields() {
return {
company: this.belongsTo(Company, 'company_id'),
};
}
}
export default User;公司
import { Model } from '@vuex-orm/core';
import { User } from './models';
export class Company extends Model {
// This is the name used as module name of the Vuex Store.
static entity = 'companies';
static fields() {
return {
account_manager: this.belongsTo(User, 'account_manager_id'),
};
}
}
export default Company;为了避免依赖循环,我紧跟https://vuex-orm.org/guide/model/single-table-inheritance.html#solution-how-to-break-cycles的解决方案,将Company和User导入到models.js中
模型
export * from './company';
export * from './user';然而,我仍然从linter得到依赖循环错误。
我已经没有点子了。
代码示例:https://github.com/mareksmakosz/vuex-orm-dependency-cycle
发布于 2020-05-18 06:49:26
这只是ESLint强制执行规则,如果你使用airbnb,你无法避免它。如果eslint:recommended真的很痛苦,那就考虑一下它。
或者,如果您想要将airbnb和您的模型分开,我建议删除导入,并使用实体将您的关系定义为字符串。
this.belongsTo('companies', 'company_id')
this.belongsTo('users', 'account_manager_id')https://stackoverflow.com/questions/61755567
复制相似问题