vue-service-state
v1.0.32
Published
基于vue的响应式状态管理插件
Downloads
13
Maintainers
Readme
简介:
- vuex-service-state 是对基于Vue的一个状态管理插件、降低来代码的耦合度
- 通过装饰器来注入State 或者 Action
使用:
yarn add vuex-service-state
//service/index.ts
import {Service, Action, ServiceAction, ServiceState} from "vue-service-state";
new Service();
//用来储存状态
@ServiceState
class User {
public name: any = 100;
}
//用来标示一个action组件
@ServiceAction
class UserAction extends Action{
public setName(): void {
this.commit("User.name", 200);
}
}
//Test.vue
import {Component, Vue} from "vue-property-decorator";
import {AutoWriteState, AutoWriteAction} from "vue-service-state";
@Component
export default class TestService extends Vue {
//这里的属性名称必须和Service里面定义State的类名称保持一致
@AutoWriteState
public User: any;
//这里的属性名称必须和Service里面定义Action的类名称保持一致
@AutoWriteAction
public UserAction: any;
public update() {
this.UserAction.setName();
}
}