Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

How to access the database #63

Open
rwatts3 opened this issue Aug 17, 2017 · 1 comment
Open

How to access the database #63

rwatts3 opened this issue Aug 17, 2017 · 1 comment

Comments

@rwatts3
Copy link

rwatts3 commented Aug 17, 2017

Greetings,

What is the best way to access the database?
I believe using vuex store would be the best way to go but i'm not sure how to access the database within the store.

This question is available on Nuxt.js community (#c53)
@alanaasmaa
Copy link

alanaasmaa commented Nov 7, 2017

I would use adonis to do stuff with database.

Then create some api routes that vue/nuxt will call for data. And then you can play with your data. I think that is the only (at least right) way to do it.

http://adonisjs.com/docs/3.2/adonis-blog-part3

for an example a way to get Locale

app\Controllers\Http\LangController.js

'use strict'

const Antl = use('Antl')

class LangController {
  async get ({ response }) {
    response.json({
      lang: Antl.getLocale()
    })
  }
}

module.exports = LangController

start/routes.js

const Route = use('Route')
Route.get('lang', 'LangController.get')
Route.any('*', 'NuxtController.render')

Then in vue:

<script>
import axios from '~/plugins/axios'

export default {
  methods: {
    changeLanguage (lang) {
      axios().get('/lang').then((response) => {
        console.log(response)
      }).catch((error) => {
        console.log(error)
      })
    }
  }
}
</script>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants