Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaofan2406/vue-vue
Simple state management helper that uses a vue instance as the data layer
https://github.com/xiaofan2406/vue-vue
Last synced: about 1 month ago
JSON representation
Simple state management helper that uses a vue instance as the data layer
- Host: GitHub
- URL: https://github.com/xiaofan2406/vue-vue
- Owner: xiaofan2406
- Created: 2016-10-17T00:28:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-28T05:24:11.000Z (about 3 years ago)
- Last Synced: 2024-11-21T13:09:36.832Z (2 months ago)
- Language: Vue
- Homepage:
- Size: 84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vue-Vue
Simple state management helper that uses a vue instance as the data layer> the root store (`this.$store`) is just an instance of vue
### Install
```
npm install --save vue-vue
```### Usage
```js
// tell Vue to use VueVue plugin
import VueVue from 'vue-vue';Vue.use(VueVue);
// define a module
class CounterStore {
constructor(init = {}) {
this.count = init.count || 0;
}increment() {
this.count++;
}decrement() {
this.count--;
}
}// create a VueVue store
const store = VueVue.createStore({
counterStore: new CounterStore()
});// tell root Vue instance to use the store
new Vue({
el: '#app',
store
});// use the store in any component
...
computed: {
count(): {
return this.$store.counterStore.count;
}
}
...
```### API
##### createStore(modules, initialState = null)
- Arguments:
- `{Object} modules`
- `{Object} initialState`, optional- Note:
- `modules` and `initialState` should have matching keys, unmatched will be ignored
- the type of a module should not matter, as long as it has a property called `constructor` and uses it for initialization