1

我正在尝试使用来自https://github.com/scotley/vuex-orm-decorators#readme的 npm 包 'vuex-orm-decorators'

当我尝试插入数据库时​​,出现错误TypeError: this.types is not a function

实体看起来像这样

import { Model } from "@vuex-orm/core";
import { NumberField, OrmModel, StringField } from "vuex-orm-decorators";

@OrmModel("races")
export default class Race extends Model {
  @NumberField()
  public ID!: number;

  @StringField()
  public Name!: string;
}

商店看起来像这样:

import Vue from "vue";
import Vuex from "vuex";
import { ORMDatabase } from "vuex-orm-decorators";

Vue.use(Vuex);

export default new Vuex.Store({
  .
  .
  .
  plugins: [ORMDatabase.install()]
});

另外,也许这是一个线索……在 Vuex-Orm 中, this.setters 返回一个值,但 this.setters('all') 返回未定义。

/**
 * Get all records.
 */
Model.all = function () {
   return this.getters('all')();
};

从未定义的基本字段和函数来看,vuex-orm 数据库似乎没有正确设置。有任何想法吗?

我试图为 vuex-orm-decorators 创建一个 stackoverflow 标签,但我还没有达到 1500 rep,所以我只是将它标记为 vuex-orm。

4

1 回答 1

0

在 Vuex-ORM单表继承文档中定义的函数的实现中, vuex-orm-decorators包中有一个小错误。types

我创建了一个分支,在其中修复了这个简单的问题,并创建了一个拉取请求来更新原始包。

最后,我必须从我对这个包的深入研究中指出,它还没有完全准备好在 Vuex-ORM 中构建的表继承功能,但仍然非常适合简单的用例。

于 2020-01-08T20:27:21.553 回答