| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- export const types = {
- SET_USER_INFO: 'SET_USER_INFO',
- SET_IS_LOGIN: 'SET_IS_LOGIN',
- SET_CAPTCHA: 'SET_CAPTCHA'
- }
- export const state = function (){
- return {
- userInfo: {
- id: '',
- name: '',
- },
- isLogin: false,
- captcha: '1'
- }
- }
- export const mutations = {
- [types.SET_USER_INFO](state, userInfo) {
- state.userInfo = userInfo;
- },
- [types.SET_IS_LOGIN](state, isLogin) {
- state.isLogin = isLogin;
- },
- [types.SET_CAPTCHA](state, captcha) {
- state.captcha = captcha;
- }
- }
- export const actions = {
- setUserInfo({ commit }, userInfo) {
- commit(types.SET_USER_INFO, userInfo);
- },
- async nuxtServerInit ({ commit }, { req }) {
- console.log(req.session);
- if (req.session.user) {
- commit(types.SET_USER_INFO, req.session.user)
- }
- commit(types.SET_CAPTCHA, 'req.session.captcha')
- if (req.session.captcha) {
- commit(types.SET_CAPTCHA, req.session.captcha)
- }
- }
- }
- export const getters = {
- userInfo: state => state.userInfo,
- isLogin: state => state.isLogin,
- captcha: state => state.captcha
- }
- export default {
- state,
- mutations,
- actions,
- getters
- }
|