0

我在用着

"vuex-orm/core": "^0.31.2",
"vuex": "^3.1.0"

我已经创建了模型“列表”和模块“列表”并且运行良好。我创建模型“书签”和模块“书签”的方式相同。但返回错误:[vuex] 未知操作类型:entities/bookmarks/insertOrUpdate

Bookmark.js(模型)

import { Model } from '@vuex-orm/core'
import Listing from '@/models/Listing.js'
export default class Bookmark extends Model {
    static entity = 'bookmarks'
    static fields () {
        return {
            id: this.increment(),
            created_at: this.attr(''),
            updated_at: this.attr(''),
            listing_id: this.number(0),
            listing: this.belongsTo(Listing, 'listing_id'),
            user_id: this.number(0),
        }
    }
}

书签.js(模块):

export default {
    namespaced: true
}

数据库.js

import { Database } from '@vuex-orm/core' 

import Listing from '@/models/Listing'
import Bookmark from '@/models/Bookmark'

import listings from './modules/listings'
import bookmarks from './modules/bookmarks'

const database = new Database()

database.register(Listing, listings)
database.register(Bookmark, bookmarks)

export default database

存储/index.js

import VuexORM from '@vuex-orm/core'
import database from '@/database'

export const plugins = [VuexORM.install(database)]

更新商店的代码:

Bookmark.insertOrUpdate({
  data: result.data.booking;
}).then((entities) => {
  console.log('bookmark success');
});
Listing.insertOrUpdate({
  data: result.data.listing
}).then((entities) => {
  console.log('listing success');
});

列表商店正在成功更新

4

0 回答 0