@indzz/nuxt-api-manager
v1.0.2
Published
Auto-load API functions for nuxt component
Downloads
17
Readme
@indzz/nuxt-api-manager
Setup
nuxt.config.js
{
buildModules: [
// Simple usage
'@indzz/nuxt-api-manager',
// With options
['@indzz/nuxt-api-manager', { /* module options */ }],
]
}Using top level options
{
buildModules: [
'@indzz/nuxt-api-manager',
],
api: {
/* module options */
dir: 'api',
excludes: ['index.js', 'base.js'],
}
}Options
dir
Default: 'api'
excludes
Default: ['index.js', 'base.js']
The files in the array will be excluded from registering to the API manager.
Usage
This module will inject a global variable $api to your Vue instance, so you can call the API classes with this.$api.apiClassName().
If dir option is set to api, put all your API files in the ./api/ folder.
For example, if you have defined MyAccountApi class, you can call it with this.$api.myAccount().
// File: ./api/my_account.js
class MyAccountApi {
submit() { }
}
export default MyAccountApiIf you export multiple classes from one file, you will get both this.$api.user() and this.$api.role().
// File: ./api/user.js
class UserApi {
profile() { }
}
class RoleApi {
list() { }
}
export { UserApi, RoleApi }