콘텐츠로 이동
Search

Vue:Components:App

lastmod 2026-11-10created 2021-07-083 edits

이 문서는 Vue 애플리케이션의 최상위 컴포넌트 App.vue 의 스크립트 부분을 정리한 예제이다. 모든 화면이 이 컴포넌트 안에서 렌더링되므로, Vuetify 테마의 다크 모드 전환, i18n 로케일 설정, API 클라이언트의 기본 URL 지정처럼 앱 전체에 걸친 초기화를 mounted 같은 생명주기 훅에서 처리한다. 같은 내용을 Options API 로 쓴 JavaScript 버전과 vue-property-decorator 의 클래스 문법으로 쓴 TypeScript 버전을 나란히 비교한다.

JavaScript

export default {
  name: "App",
  components: {},
  data() {
    return {};
  },
  methods: {},
  computed: {
    dark() {
      return this.$vuetify.theme.dark;
    },
  },
  watch: {
    dark() {
      this.$vuetify.theme.dark = this.dark;
    },
  },
  created() {
    // this.$api.setUrl(this.$local.getters['etc/getApiUrl']);
  },
  mounted() {
    this.$vuetify.lang.current = "ko";
    this.$i18n.locale = this.$store.getters["language/getLanguage"];
    this.$api.setUrl(this.$localStore.getters["etc/getApiUrl"]);
  },
  beforeDestroy() {},
};

TypeScript

위의 #JavaScript 버전을 TypeScript 버전으로 변경하면 다음과 같다:

import { Vue, Component, Watch } from "vue-property-decorator"

@Component
export default class App extends Vue {
  created() {
    // this.$api.setUrl(this.$local.getters['etc/getApiUrl']);
  }

  mounted() {
    this.$vuetify.lang.current = "ko";
    this.$i18n.locale = this.$store.getters["language/getLanguage"];
    this.$api.setUrl(this.$localStore.getters["etc/getApiUrl"]);
  }

  beforeDestroy() {
    // EMPTY.
  }

  get dark(): boolean {
    return this.$vuetify.theme.dark;
  }

  @Watch("dark")
  onChangedDark() {
    this.$vuetify.theme.dark = this.dark;
  }
}

See also

author Zer0, MCPBot sitemap