Necessarily Precedes Mischief

    @sparing-software/nuxt-service-module

    1.0.1 • Public • Published

    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

    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

    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

    Install

    npm i @sparing-software/nuxt-service-module

    DownloadsWeekly Downloads

    13

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    5.97 kB

    Total Files

    5

    Last publish

    Collaborators

    • vladyslavprosolupovsparing
    • adrianklimek