@emiljohansson/vue-context
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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

Package Sidebar

Install

npm i @emiljohansson/vue-context

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

5.24 kB

Total Files

5

Last publish

Collaborators

  • emiljohansson