1.0.1 • Published 3 years ago

vue-data-store v1.0.1

Weekly downloads
27
License
-
Repository
github
Last release
3 years ago

vue-data-store

Simple vue global store

Install

npm install vue-data-store

Creating store

// store.js

// Vue 3
import createStore from 'vue-data-store/hook'

// Vue 2
// import createStore from 'vue-data-store'

const store = createStore({
    count: 1,
    arr: []
})

export default store

Using store data

import store from './store'

//Vue 3
export default {
  setup() {
    const count = store('count')
    const arr = store('arr')

    return {
      count,
      arr
    }
  },
  methods: {
    increment(){
      this.count ++
    },
    add() {
        let l = String.fromCharCode(this.arr.length + 65)
        this.arr.push(l)
    }
  }
}

//Vue 2
export default {
  data:()=>({
      count,
      arr
  }),
  created() {
    this.count = store.attach('count', this)
    this.arr = store.attach('arr', this)
  },
  methods: {
    increment(){
      store.set('count', this.count + 1)
    },
    add() {
        let arr = this.arr
        let l = String.fromCharCode(arr.length + 65)
        
        arr.push(l)
        store.set('arr', arr)
    }
  }
}
1.0.1

3 years ago

1.0.0

3 years ago

0.1.4

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago