1

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: {
  users() {
 // this wont work as $db is undefined
    User () {
     return this.$store.$db().model('users')
    },
    users () {
     return this.User.all()
    }

    }

What am I doing wrong here?

Abhilash
  • 2,864
  • 3
  • 33
  • 67

1 Answers1

0

In your store/index.js you have to export state to activate Vuex store. Add this to the file:

export const state = () => ({})
dappiu
  • 926
  • 10
  • 11