vue-j-store
vue2.X 模块化状态管理,解决store文件过大,命名空间过长等问题。其实只是一种思路。
用法尽可能与vuex保存一致,(注意)其中对map方法进行了扩展,调用方式也不一样。
npm
$ npm install vue-j-store
优点对照
相信用过的人都想过store过大,actions过多而头痛吧。换个角度不好吗?一对一,删除方便,查找方便,读取变量也方便。
Usage
main.js
; ; Vue;
componentA
componentA/store.js
; ;
componentA/index.vue
<template> <div> <h4>$storestatecount</h4> <button @click="$store.commit('inc')">加</button> <button @click="$store.commit('reduce')">减</button> </div></template> <script> ; store </script>
componentB
componentB/store.js
; ;
componentB/index.vue
<template> <div> <h4>count</h4> <button @click="ajaxRequest">请求</button> </div></template> <script> ; computed: { return this$storestatecount; } methods:store store </script>
map使用惯例
store; //全部 store; //等同于["count"] store; store; //同上 ... ... store; //同上 ... ... store; //同上 ... ...