0.1.9 • Published 4 years ago

vuex-simple-state v0.1.9

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Vuex Simple State

Works with Vue 2 and Vue 3

Installation

npm install vuex-simple-state --save

or

yarn add vuex-simple-state

Add the project to your main.js

import store from './store'
...
import State from 'vuex-simple-state'

Vue.use(State)

Add the mutation to your store

import { mutateState } from 'vuex-simple-state'
...
  state: {
    email: 'me@example.com',
    user: {
      email: ''
    }
  }
  mutations: {
    mutateState //Add the mutation here
  },
...

Add the directive to your code

<input v-state="[element name]">

<input v-state="'email'">

For modules or nested elements

<input v-state="'[your state element].[child element]'">

or

<input v-state="'[module].[your state element]'">

or

<input v-state="'[module].[your state element].[child element]'">

Vue 2 Example

<input v-state="'user.email'">
<input v-state="'module.email'">
<input v-state="'module.customer.email'">


// Make the store state you are bound to reactive to a data element or computed field
...
<input v-state="element">
...
  data() {
    return {
      element: 'employee.email'
    }
  }
...

Vue 3 Example

<input v-state="'user.email'">
<input v-state="'module.email'">
<input v-state="'module.customer.email'">

<input v-state="data.element"> //Reactive element
...
  setup() {
    const data = reactive({
      element: 'employee.email'
    })
    return {
      data
    }
  }
...

Events

State is sync'd on the input event, but you can update on any event

<input v-state.blur="'user.email'">             //Updates state on focus loss
<input v-state.my-custom-event="'user.email'">  // You'll need to manually dispatch custom events
0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago