1.1.0 • Published 2 years ago
@bildvitta/vuex-store-module v1.1.0
vuex-store-module
VuexStoreModule
is a generic Vuex store module for keep it simple. Use your time for what you really needs.
Getting Started
Installation
npm i @bildvitta/vuex-store-module
Usage
To use the VuexStoreModule
you have to setup the API, you can pass an instance of axios or another API like axios.
import VuexStoreModule from '@bildvitta/vuex-store-module'
import axios from 'axios'
const storeModule = new VuexStoreModule({ apiService: axios })
// you can pass your own API like axios to apiService
export default storeModule
Inside your store
let's import our instance of VuexStoreModule
.
import storeModule from 'some-path'
export default storeModule.createStoreModule('posts')
Options
const storeModule = new VuexStoreModule({
apiService: undefined // instance of API
})
storeModule.createModule(
'resource', // name of store and usually used as endpoint of API
options: {
idKey: 'id', // property used for find in object and arrays
perPage: 12, // results per page
createURL: '/', // custom URL for create
destroyURL: ({ id }) => `/${id}`, // custom URL for destroy
fetchFiltersURL: '/', // custom URL for fechFilters
fetchFormURL: ({ id }) => `/${id}`, // custom URL for fechForm
fetchListURL: '/', // custom URL for fechList
fetchSingleURL: ({ form, id }) => `/${id}`, // custom URL for fechSingle
replaceURL: ({ id }) => `/${id}`, // custom URL for replace
updateURL: ({ id }) => `/${id}`, // custom URL for update
methods: [ // methods that the VuexStoreModule will return
'CREATE',
'DESTROY',
'FETCH_FILTERS',
'FETCH_FORM',
'FETCH_LIST',
'FETCH_SINGLE',
'REPLACE',
'UPDATE'
]
}
)
Methods
Name | API Method | Arguments | description |
---|---|---|---|
create | POST | { payload, url } | Creates an object and return it. |
destroy | DELETE | { id, params } | Deletes an object and return it. |
fetchFilters | GET | { params, url } | Returns filters from an endpoint. Used for dynamic filters. |
fetchForm | GET | { id, params, url } | Returns an object from /new if no resource or url is passed |
fetchList | GET | { filters = {}, increment, ordering = [], page = 1, limit, search, url } | Returns a list. |
fetchSingle | GET | { form, id, params, url } | Returns an object. |
replace | PUT | { id, payload, url } | Update fields in an object. |
update | PATCH | { id, payload } | Update all fields in an object. |
1.1.0
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago
0.0.22
3 years ago
0.0.21
4 years ago
0.0.20
4 years ago
0.0.19
4 years ago
0.0.18
4 years ago
0.0.17
4 years ago
0.0.16
4 years ago
0.0.15
4 years ago
0.0.14
4 years ago
0.0.13
4 years ago
0.0.11
4 years ago
0.0.12
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8-beta.0
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.1-beta.0
4 years ago
0.0.1
4 years ago