pinia-class-component
ECMAScript / TypeScript decorator for class-style Pinia store.
47,479
39
| Install | |
|---|---|
npm install pinia-class-component |
|
| Latest Version: | 0.9.4 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | May 19, 2022 |
| Links: | GitHub · npm |
Maintainer: moecopilot
Pinia Class Component
ECMAScript / TypeScript decorator for class-style Pinia store.
Getting Started
npm install pinia-class-component || yarn add pinia-class-component
Document
import { Store, Pinia } from 'pinia-class-component'
@Store
export class User extends Pinia {
userInfo = {
name: '',
avatar: '',
token: '',
}
get token() {
return this.userInfo.token
}
async login(form) {
// let data = await axios.get...
// this.userInfo = data
}
}
// usage
const user = new User()
user.login(...)
It be equal to:
import { defineStore } from 'pinia'
export const useUser = defineStore('User', {
state: () => ({
userInfo: {
name: '',
avatar: '',
token: '',
},
}),
getters: {
token(state) {
return state.userInfo.token
},
},
actions: {
async login(form) {
// ...
},
},
})
// usage
const user = useUser()
user.login(...)
Inspired by vue-class-component
License
Related Packages
@haixing_hu/pinia-decorator
Provides class fields decorators for Pinia and vue3-class-component.
2,676
2
vue-component-static-loader
A loader for Webpack that statically parses Vue class components with specified...
1,128
2
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.9.4 | ^3 | MIT | |
| 0.9.3 | ^3 | MIT | |
| 0.9.2 | ^3 | MIT |