index.js 1.24 KB
import Cookie from 'js-cookie';

export const state = () => ({});
export const mutations = {};
export const actions = {
  //새로고침마다 호출되는 함수
  async nuxtServerInit({dispatch}, {req}) {
    try {
      const cookie = req.headers.cookie.split('=')[1];
      console.log(cookie);
      await dispatch('user/loadMe', {cookie});
      // await dispatch('post/loadPosts', {reset: true});
      // await dispatch('waitingRoom/loadChatMe');
    } catch (e) {
      console.error(e);
    }
  }
};


// 1) state : 데이터 정의
// users, groups, user,files, file
// 2) mutation : state에 있는 데이터들을 수정하는 작업
// user => 이름이 바뀌면 state에 있는 user 정보를 가지고 와서 수정하는 곳
// 3) action: 서버에다가 데이터를 요청하는 작업
// 서버에서 user 정보를 받아서 mutation에 state에 있는 user 정보를 내가 받은 정보로 수정하라고 요청


// state에서 데이터를 정의할 때 username, password 이런식으로 작은 단위로는 정의를 잘 안해
// user정보로 묶음으로 정의하는 거든
// user: { 'username' : '정수연', 'password': 'wjdtndus'}
// file: { 'filename': , 'createdAt', 'deletedAt', 'isFolder'}
// user: null, '', 0, True, False