Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
flyingboy007 opened this issue Jan 29, 2020 · 7 comments
Closed

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

flyingboy007 opened this issue Jan 29, 2020 · 7 comments
Labels
released The issue was implemented and it is released publicly
Milestone

Comments

@flyingboy007
Copy link

flyingboy007 commented Jan 29, 2020

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?

@cuebit
Copy link
Member

cuebit commented Jan 29, 2020

@flyingboy007 you seem to have User and users within a users method. Is this a typo?

@flyingboy007
Copy link
Author

flyingboy007 commented Jan 29, 2020

@flyingboy007 you seem to have User and users within a users method. Is this a typo?

Was a typo. Sorry for that. Updated

@cuebit
Copy link
Member

cuebit commented Feb 4, 2020

By way of update @flyingboy007, there is a known issue when using Vuex ORM 0.35.x with Nuxt so it may be this is a conflicting issue with #544

Will keep you posted.

cuebit added a commit to cuebit/vuex-orm that referenced this issue Feb 4, 2020
contribu pushed a commit to contribu/vuex-orm that referenced this issue Feb 13, 2020
@kiaking
Copy link
Member

kiaking commented Mar 4, 2020

@flyingboy007 #544 is fixed with Vuex ORM 0.36.1. Could you try this one and see if it fixed this one as well?

@kiaking kiaking added the need more info Need more info to decide what action to take for the issue label Mar 4, 2020
@kiaking kiaking added this to the v1.0.0 milestone Mar 4, 2020
@flyingboy007
Copy link
Author

@kiaking Great I will try and update

@flyingboy007
Copy link
Author

Thank you for the fix. It is working now.

@kiaking
Copy link
Member

kiaking commented Mar 9, 2020

@flyingboy007 Wonderful to hear that!!! Thank you for confirming 👍

@kiaking kiaking added released The issue was implemented and it is released publicly and removed need more info Need more info to decide what action to take for the issue labels Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released The issue was implemented and it is released publicly
Projects
None yet
Development

No branches or pull requests

3 participants