简介:一个简易版的vue状态管理包,支持完全体typescript。
Intro: Vue state management plug-in,Simple version of vuex,support typescript。
安装/Install
npm/cnpm install vue-lazy-store --save / yarn add vue-lazy-store
使用/Use
使用方法跟vuex类似,基本可以无缝切换.
Similar to vuex, it can be switched seamlessly.
store-ts
// src/store/index;Vue;public count: number = 0;public : numberreturn count ++;Storepublic text1: Text1;public {super;thistext1 = ;// 请在最后面激活store / Activate store at the endthis;}// ssr;// csr;declare module 'vue/types/vue'interface Vue$store: BaseStore;declare module 'vue/types/options'interface ComponentOptions<V extends Vue>store?: BaseStore;
store-js
;;Vue; const text1 = count: 0 { thiscount++; }const store = text1;store; ;
.vue-ts
// support ts;@Component<LocalVue>{}public {return this$storetext1;}public {return thistext1count; // 0}public {thistext1;console; // 1;}
.vue-js
computed:{return this$storetext1;}{return thistext1count;}{thistext1;console; // 1;}
ssr客户端接管状态 / ssr client takeover state
if window__INITIAL_STATE__store;
tips
状态变更上不像vuex那样严谨,需要commit状态为true时,才能更新。但是使用起来非常简单,
而且支持class写,进而完全支持ts,欢迎进一步完善。
State changes are not as rigorous as vuex, and they need to be true before they can be updated. But it's very simple to use.
And support class writing, and then fully support ts, welcome to further improve
之前想好的easy,simple之类的词语,一律用不了,那就不如叫它懒人store吧!
Previously thought of easy, simple and other words, are no longer used, it would be better to call it lazy store!