vuex-model-helper

Vuex model helper


Keywords
vue.js, eslint, jest, travis-ci, vue, vuex, yarn
License
ISC
Install
npm install vuex-model-helper@0.0.6

Documentation

vuex-model-helper

travis-build-result

Help you use vuex and v-model more happier

Installation

yarn add vuex-model-helper
# or by npm
npm install --save vuex-model-helper

How to use vuex-model-helper

  1. Use mutationGenerator() to generate your v-model mutations
import Vuex from 'vuex';
import { mutationGenerator } from 'vuex-model-helper';

const mutations = {
  ...mutationGenerator([
    'userName',
  ]),
};
const state = {
  userName: '',
};
const store = new Vuex.Store({
  mutations,
  state,
});
  1. In your *.vue file, call computedGenerator() and methodsGenerator() to generate computed object and mutation methods.
<template>
  <div>
    User Name:
    <input
      type="text"
      v-model="userName"
    >
  </div>
</template>

<script>
import { mapMutations } from 'vuex';
import {
  computedGenerator,
  methodsGenerator,
} from 'vuex-model-helper';

export default {
  computed: {
    ...computedGenerator([
      'userName',
    ]),
  },
  methods: {
    ...mapMutations([
      ...methodsGenerator([
        'userName',
      ]),
    ]),
  },
};
</script>
  1. And then you can "change" your v-model and then trigger your mutation (CHANGE_USER_NAME).

More example