기본 구조

MVVM 모델 View: DOM, Model: Javascript Object, VM: Vue (내부 리스너를 통해 model 변경, directives를 통해 변경사항이 view에 반영)

Vue에서 중요한 개념들

Vue 인스턴스

< script>
export default {
  name: 'Navbar',
  props: {
    topbarColor: {
      type: String,
      default: '#2962ff'
    },
    title: {
      type: String
    },
    logo: {
      type: String
    },
    user: Object
  },
  data: () => ({
    indexActive: 0,
    showToggle: false,
    searchvalue: ''
  }),
  methods: {
    logout () {
      if (confirm('정말 로그아웃 하시겠습니까?')) {
        this.$store.dispatch('AUTH_LOGOUT').then(() => {
          this.$router.replace('/login');
        }).catch((e) => {
          console.log(e);
        });
      }
    }
  }
}; </script>  // 이런식으로 export 하면 vue instance 생성

추가적인 옵션, 데이터 참고 → https://kr.vuejs.org/v2/api/#옵션-데이터

인스턴스 라이프사이클

vue instance에는 LifeCycle 존재

https://kr.vuejs.org/v2/guide/instance.html#라이프사이클-다이어그램

그리고 life Cycle에 대한 hook이 존재, 해당 hook에 원하는 동작 실현 가능.

{
  name: 'MainContainer',
  data: () => ({
    title: '',
    topbarColor: '',
    user: {},
    sidebarLinks: []
  }), ...
  created () {
    this.$store.commit('GET_USER');
    this.topbarColor = this.$store.state.themeColor;
    this.user = this.$store.state.auth.user;
    this.sidebarLinks = this.$store.state.auth.user.accessibleMenus;
  }
}; // MainContainer 생성시 해당 created hook이 발동 , 테마 컬러와 auth 관련 부분 설정