fix: login state lost #20

master
iczer 6 years ago committed by chenghx
parent 22561da68f
commit 3053544b59
  1. 9
      src/main.js
  2. 11
      src/store/modules/account.js

@ -9,6 +9,7 @@ import axios from 'axios'
import message from 'ant-design-vue/es/message'
import '@/mock'
import store from './store'
import PouchDB from 'pouchdb'
Vue.prototype.$axios = axios
Vue.prototype.$message = message
@ -21,5 +22,11 @@ new Vue({
router,
store,
components: { App },
template: '<App/>'
template: '<App/>',
mounted () {
var db = new PouchDB('admindb')
db.get('currUser').then(doc => {
this.$store.commit('account/setuser', doc.user)
})
}
})

@ -1,3 +1,7 @@
import PouchDB from 'pouchdb'
var db = new PouchDB('admindb')
export default {
namespaced: true,
state: {
@ -6,6 +10,13 @@ export default {
mutations: {
setuser (state, user) {
state.user = user
db.get('currUser').then(doc => {
db.put({
_id: 'currUser',
_rev: doc._rev,
user: user
})
})
}
}
}

Loading…
Cancel
Save