1.0.1 • Published 5 years ago
@sparing-software/nuxt-service-module v1.0.1
Nuxt service module
Services integration with Nuxt.js
Installation
Install package in your project
$ npm install @sparing-software/nuxt-service-module
Configuration
Add module to nuxt.config.js
modules: [
'@sparing-software/nuxt-service-module'
// or
['@sparing-software/nuxt-service-module', {
// ... options
}]
]
Options
Option | Description | Default |
---|---|---|
httpClient | Relative path to your favourite httpClient | null (httpClient received in service will be set to $axios. Caveat: @sparing-software/nuxt-service-module must be set before @nuxtjs/axios module) |
Example
['@sparing-software/nuxt-service-module', {
httpClient: 'plugins/axios'
}]
And in @/plugins/axios.js
const axios = require('axios')
export default axios // or module.exports = axios
Usage
- Create
service
folder in your root directory - Add service by creating js file - for example:
@/service/books.js
will createbooks
service
export default httpClient => ({
getAll () {
return httpClient.get('/books')
},
getById (id) {
return httpClient.get('/books?id=' + id)
}
})
books
service is now accessible all over the app:
- Components:
this.$service.books.getAll()
- Vuex actions:
this.app.$service.books.getAll()
- The Context:
ctx.$service.books.getAll()
Contributing
Want to help improve this module? Great!
Project is open-source so fork repo and join us!
License
MIT License © Sparing Interactive