Creates a React like context between parent and child components.
https://emiljohansson.github.io/vue-context/demo/build/
$ npm install @emiljohansson/vue-context
import VueContext from '@emiljohansson/vue-context'
Vue.use(VueContext)
const store = {
state: {
value: 42
},
methods: {
setValue (state, newValue) {
state.value = newValue
}
}
}
const root = {
data () {
return {
// If you need to use the same data in the provider.
// Otherwise you can create this directly in provide()
appContext: this.$createContext(store)
}
},
provide () {
return {
appContext: this.appContext
}
}
}
const childComponent = {
inject: ['appContext']
}
MIT © Emil Johansson