pinia-facing-decorator
Version:
93 lines (73 loc) • 1.47 kB
Markdown
# pinia 装饰器模块
使用装饰器来编写你的pinia,配合[vue-facing-decorator(npm)](https://www.npmjs.com/package/vue-facing-decorator)、[vue-facing-decorator(github)](https://github.com/facing-dev/vue-facing-decorator)
使用效果更加!
## 项目简介
- 使用技术:pinia
- 参考项目:vuex-module-decorators
## 安装
```
npm install pinia-facing-decorator
```
## 使用
### 代码
```
import {PiniaModule, Module, Plugins, Actions} from "@/pinia-facing-decorator";
export default class Test extends PiniaModule {
name: string = "name";
age: number = 23;
get getName() {
return this.name;
};
get getAge() {
return this.age;
};
setName(name: string) {
this.name = name;
}
setSystemConfig(age: number) {
this.age = age;
}
addAge(age: number) {
this.age = age;
}
debounce = {
addAge: 3,
}
}
```
就像
```
import {defineStore} from "pinia";
const testUserStore = defineStore("user", {
state: () => {
return {
name: "name",
age: 23
};
},
getters: {
getName: (state) => state.name,
getAge: (state) => state.age
},
actions: {
setName(name: string) {
this.name = name;
},
setAge(age: number) {
this.age = age;
},
addAge(age: number) {
this.age = age;
}
},
debounce: {
addAge: 3,
}
});
export default testUserStore;
```