0.0.3 • Published 5 years ago

@emiljohansson/vue-context v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

vue-context Build Status

Creates a React like context between parent and child components.

Demo

https://emiljohansson.github.io/vue-context/demo/build/

Install

NPM

$ npm install @emiljohansson/vue-context
import VueContext from '@emiljohansson/vue-context'

Vue.use(VueContext)

Example

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']
}

License

MIT © Emil Johansson

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago