vuex-class-state2way
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

vuex-class-state2way

TypeScript decorator to create getters/setters for a Vuex state.

The main purpose is to use v-model directive without the overhead of manually creating simple getters and setters.

Check vuex-class repository for a lot more Vuex decorators!

Dependencies

Installation

$ npm install --save vuex-class-state2way
# or 
$ yarn add vuex-class-state2way

Usage

  • Get variable_name from the state, and commit "mutation name" to update this variable in the state
@State2Way("mutation name") variable_name
  • Get variable_name from the state and set its value to the variable other_name, and commit "mutation name" to update this variable in the state
@State2Way("mutation name", "variable_name") other_name
  • To get a deep value, you can do both:
@State2Way("mutation name", state => state.foo.bar) fooBar // you get type checking
@State2Way("mutation name", "foo.bar") fooBar

Example

import Vue from 'vue'
import Component from 'vue-class-component'
import { State2Way } from 'vuex-class-state2way'
 
@Component
export class Comp extends Vue {
    @State2Way('updateFoo', 'foo') stateFoo
    @State2Way('updateBar') bar
    @State2Way('updateFooBar', 'foobar.example') stateFooBarExample
    @State2Way('updateFooBar', state => state.foobar.example) stateFooBarExemple2
}

Readme

Keywords

none

Package Sidebar

Install

npm i vuex-class-state2way

Weekly Downloads

13

Version

1.0.1

License

MIT

Unpacked Size

3.34 kB

Total Files

4

Last publish

Collaborators

  • scleriot