VuexRailsPlugin
A Vuex plugin that easily maps Rails resources to Vuex modules
The idea of this plugin is to easily incorporate conventional rest endpoints defined when scaffolding Rails resources and map the responses to appropriate state in Vuex. ex. resources :posts
generates the following endpoints:
- GET|POST /posts
- GET|PUT /posts/:id
- DELETE /posts/:id
Install
$ npm i vuex-rails-plugin
Usage
The plugin can be imported into any Vuex store like so:
// store.jsVue Vuex
This example defines Vuex modules for 'posts' and 'categories' namespaces. It supports the following state:
- all - items returned from the index action
- current - set when the show action is called
- error - set if any errors occur such as validations
The state can be mapped to any Vue component using mapState
// some-component.vue computed: ...
Actions can also be called by using mapActions
// some-component.vue // ... methods: ...
Params are supported
this
Use directly in a form
{ return newPost: title: '' body: '' }
Title Body Submit
Promises supported
// ... methods: { this }
TODO
- Support nested resources ex.
/categories/:category_id/posts
- Support other options that may be necessary to support custom getters, filters, etc.