0.0.6 • Published 8 years ago

generator-vuex-starter v0.0.6

Weekly downloads
8
License
MIT
Repository
github
Last release
8 years ago

generator-vuex-starter NPM version Build Status Dependency Status Coverage percentage

a vuex starter

Installation

First, install Yeoman and generator-vuex-starter using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-vuex-starter

Then generate your new project:

yo vuex-starter

Use step

1: create type and state

cd $prodir/src/store
export const USER_NAME = "user_name";

const commonState = {
  status:{failure:true},
  res:{}
}

const state = {
  [USER_NAME]:commonState,
}

export default state

2: add actions

import {createActions} from '../utils/index'
import * as stateType from './stateType'

function userNameGet() {
  return {
    type: stateType.USER_NAME,
    payload: {
      endpoint: '/v1/isConnect',
      options: {
        method: 'GET'
      }
    }
  }
}

export const user_name = createActions(userNameGet);

3: add mutation

import * as stateType from './stateType'
import {createMutations} from '../utils/index'

const mutations = {
  [stateType.USER_NAME]:createMutations(stateType.USER_NAME)
}

export default mutations

4: use in vue-file

import {user_name} from '../store/actions/actions'
import {USER_NAME} from '../store/stateType'

export default {
  name: 'hello',
  data() {
      return{
        status:this.$store.state[USER_NAME],
      }
    },
    computed:{
      if(this.$store.state[USER_NAME].status.success)
        return this.$store.state[USER_NAME].res;
      else 
        return {};
    },
    methods: {
      handleSelect() {
        user_name(this.$store); //dispatch actions
      }
    }
}

Bug submit

https://github.com/yhonzhao/generator-vuex-starter/issues

Getting To Know Yeoman

  • Yeoman has a heart of gold.
  • Yeoman is a person with feelings and opinions, but is very easy to work with.
  • Yeoman can be too opinionated at times but is easily convinced not to be.
  • Feel free to learn more about Yeoman.

License

MIT © Yhon

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago