0.0.2 • Published 7 years ago

vuet-store v0.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

vuet-store

Coverage Status Build Status npm npm npm

它是做什么的?

它能够监模块变化,使用localStorage存储模块状态,等下次用户访问时,再从localStorage中取出状态,适合存储用户登录状态等。

安装

npm install --save vuet-store

使用

import Vue from 'vue'
import Vuet, { mapModules, mapRules } from 'vuet'
import VuetStore from 'vuet-store'

Vue.use(Vuet)
Vuet.rule('store', VuetStore)

const vuet = new Vuet()
vuet.addModules('test', {
  data () {
    return {
      count: 0
    }
  },
  fetch () {
    this.count = 1000
  },
  plus () {
    this.count++
  },
  reduce () {
    this.count--
  }
})

const App = {
  mixins: [
    mapModules({
      test: 'test' // { 别名: '模块路径' }
    }),
    mapRules({
      store: [{ path: 'test' }] // { 规则: ['模块路径'] }
    })
  ],
  template: `
    <div>
      <div class="count">{{ test.count }}</div>
      <button @click="test.plus">plus</button> 
      <button @click="test.reduce">reduce</button> 
      <button @click="test.reset">reset</button> 
      <button @click="test.fetch">fetch</button> 
    </div>
  `
}

export default new Vue({
  el: '#app',
  vuet,
  render (h) {
    return h(App)
  }
})
0.0.2

7 years ago

0.0.1

8 years ago