0.0.20 • Published 4 years ago
store-module-test v0.0.20
vuex-store-module
VuexStoreModule
is a generic vuex store for keep it simple. Use your time for what you really needs.
Getting Started
Installation
npm i store-module-test
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 '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 // intance of API
})
storeModule.createModule(
resource, // name of store and usually used as endpoint of API
options: {
idAttribute: 'id', // property used for find in object and arrays
perPage: 12, // results per page
fetchFiltersURL: undefined, // custom URL for fechFiltersURL
replaceURL: undefined, // custom URL for replaceURL
fetchSingleURL: undefined, // custom URL for fetchSingleURL
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. |
0.0.20
4 years ago
0.0.19
4 years ago
0.0.16
4 years ago
0.0.17
4 years ago
0.0.18
4 years ago
0.0.10
4 years ago
0.0.11
4 years ago
0.0.12
4 years ago
0.0.13
4 years ago
0.0.14
4 years ago
0.0.15
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.6
4 years ago
0.0.1
4 years ago