index.html - main.js - App.vue의 흐름 파악
2022. 4. 22. 20:32ㆍVue
1. index.html : 컴포넌트들을 마운팅 해준다.
public - index.html 파일에 모아진다고 생각하면 된다. index.html 내부에 14번줄에 해당하는 <div id="app"></div>로 표시된 부분을 볼 수 있는데, 여기에 main.js에서 지정하는 컴포넌트들이 마운팅 된다.
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
2.main.js : 인스턴스를 생성하고 index.html 파일과 연결해준다.
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue.use(BootstrapVue)
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
main.js의 하단에 인스턴스를 생성하는 new Vue({ ... }) 구문이 있다.
render, $mount 등으로 작성되어 있는데 이것은 아래에 따로 표기한 코드와 같은 방식으로,
app 이라는 id를 가진 태그에 해당 인스턴스를 적용하겠다는 것이다.
즉 index.html의 <div id="app"></div> 태그를 해당 인스턴스로 꾸며주게 된다.
이외에도 main.js 부분에 BootstrapVue 등 필요한 라이브러리들을 import 해오기도 한다.
3. App.vue : 실제 컴포넌트 파일
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
즉 App.vue 파일은 하나의 컴포넌트이고, 여기에 여러 컴포넌트들을 불러와서 main.js로 넘겨주는 통합 컴포넌트라고 볼 수 있다. 컴포넌트 파일은 1. 파일구조에서 살펴본 바와 같이 <template>, <script>, <style> 부분으로 나누어져 있다.
'Vue' 카테고리의 다른 글
vue-fontawesome (0) | 2022.04.27 |
---|---|
사용자 지정 범위 슬롯을 사용하는 예시 모달 (0) | 2022.04.25 |
Mixin (0) | 2022.04.22 |
Style Guide : 우선순위 권장 (0) | 2022.04.19 |
Bootstrap 적용하기 (0) | 2022.04.13 |