此项目迁移到muse-ui下
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
demo
src
.babelrc
.eslintignore
.eslintrc
.gitignore
.npmignore
LICENSE
README.md
package.json
rollup.config.js
yarn.lock

README.md

muse-model

对vuex功能的一个增强,简化了状态流程的写法。增加按需引入model的控制

安装

npm install muse-model

or

yarn add muse-model

快速上手

// model.js
import Vue from 'vue';
import Vuex from 'vuex';
import MuseModel from 'muse-model';

export const store = Vuex.Store({
  strict: true
});

export default new MuseModel(store);
// main.js
import Vue from 'vue';
import { store } from 'model'; // model.js
import App from './App';

new Vue({
  ...App,
  store
}).$mount('app');
// count.js
export default {
  namespace: 'count', // 必须
  state: {
    count: 1
  },

  add () {
    return {
      count: this.state.count + 1
    };
  },

  sub () {
    return {
      count: this.state.count - 1
    };
  },
  doubleAdd () {
    this.add();
    return {
      count: this.state.count + 1
    }
  },

  addTimeOut () { // 异步处理
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({
          count: this.state.count + 1
        });
      }, 1000);
    });
  }
};
<template>
<div><button @click="addTimeOut()">+</button>{{count}}<button @click="sub()">-</button></div>
</template>
<script>
import model from './model';
import Count from './count';

export default model.connect({
    created () {
      console.log(this.count);
    }
}, Count);
</script>

Api

connect (component: Object, models: [Array, Object], filter: Function)

组件和model的绑定

License

MIT

Copyright (c) 2018 myron