Skip to content

Unable to access vuex-orm $db variable from store in nuxt #548

@flyingboy007

Description

@flyingboy007

Using nuxtjs with vuexorm & vuexorm-axios plugin.

/pages/index.vue

computed: {
  users() {
 // this works as expected
  return User.all()
  }
    }

plugins/vuex-orm-axios.js

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

export default ({ $axios }) => {
  Model.setAxios($axios)
}

store/index.js

import VuexORM from '@vuex-orm/core'
import VuexORMAxios from '@vuex-orm/plugin-axios'
import User from '@/models/user'


VuexORM.use(VuexORMAxios)


// Create a new database instance.
const database = new VuexORM.Database()

// Register Models to the database.
database.register(User)


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

Above all works. But in vuexorm docs it says to always fetch model from injected database instance for nuxt/ssr apps.
But if I try to access the $db variable from store it wont work as there is no $db variable inside store.

/pages/index.vue

computed: {
  // this wont work as $db is undefined
    User () {
     return this.$store.$db().model('users')
    },
    users () {
     return this.User.all()
    }
 
    }

In short calling this.$store works. But there is no $db instance in store variable. this.$store.$db() returning undefined
What am I doing wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    releasedThe issue was implemented and it is released publicly

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions