Vuex-Queries
Vuex-Queries helps you write query functions in Vuex
Usage
Write your queries in Vuex options:
const options = state: events: id: 1 author: 'a' 'b' id: 2 author: 'b' 'c' id: 3 author: 'c' 'a' queries: { return contextstateevents }
Query functions receive a context object which contains store's state and getters. You can access them by context.state
or context.getters
, or using Object Destructuring feature in ES2015:
const options = state: events: id: 1 author: 'a' 'b' id: 2 author: 'b' 'c' id: 3 author: 'c' 'a' queries: { return stateevents }
Inside module queries, context will also contain rootState
and rootGetters
.
const options = state: events: id: 1 author: 'a' 'b' id: 2 author: 'b' 'c' id: 3 author: 'c' 'a' computed: { return stateauthor0 } modules: foo: namespaced: true queries: { return rootStateevents }
Before creating Vuex store, transform the options with supportQuery(options)
method:
const store =
Use mapQueries(namespace, map)
method (which has the same parameters as other component binding helpers) to map component methods to query functions:
import mapQueries from 'vuex-queries' methods: ... { return <div> this </div> }
Changelog
v1.1.1
- update peerDependencies to allow work with Vuex 3.x
v1.1.0
- Add support for
rootState
&rootGetters