1.0.1 • Published 5 years ago

@sparing-software/nuxt-service-module v1.0.1

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

Nuxt service module

MIT license Downloads number JavaScript Style Guide

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

OptionDescriptionDefault
httpClientRelative path to your favourite httpClientnull (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

  1. Create service folder in your root directory
  2. Add service by creating js file - for example: @/service/books.js will create books service
export default httpClient => ({
  getAll () {
    return httpClient.get('/books')
  },
  getById (id) {
    return httpClient.get('/books?id=' + id)
  }
})
  1. 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