Single File Component

Single File Components μ²΄κ³„λŠ” .vue 파일둜 ν”„λ‘œμ νŠΈ ꡬ쑰λ₯Ό κ΅¬μ„±ν•˜λŠ” 방식을 λ§ν•œλ‹€. ν™•μž₯자 .vue 파일 1κ°œλŠ” λ·° μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ κ΅¬μ„±ν•˜λŠ” 1개의 μ»΄ν¬λ„ŒνŠΈμ™€ λ™μΌν•˜λ‹€.

<!--  화면에 ν‘œμ‹œν•  μš”μ†Œλ“€μ„ μ •μ˜ν•˜λŠ” μ˜μ—­ -->
<template>
<!-- HTML νƒœκ·Έ λ‚΄μš© -->
</template>
<!-- λ·° μ»΄ν¬λ„ŒνŠΈμ˜ λ‚΄μš©μ„ μ •μ˜ν•˜λŠ” μ˜μ—­ -->
<script>
exports default{
  // μžλ°” 슀크립트 λ‚΄μš©
}
</script>
<!-- template에 μΆ”κ°€ν•œ HTML νƒœκ·Έμ˜ CSS μŠ€νƒ€μΌμ„ μ •μ˜ν•˜λŠ” μ˜μ—­ -->
<style>
  /* CSS μŠ€νƒ€μΌ λ‚΄μš© */
</style>

Vue CLI

Single File Component 체계λ₯Ό μ‚¬μš©ν•˜κΈ° μœ„ν•΄μ„œλŠ” .vue νŒŒμΌμ„ μ›Ή λΈŒλΌμš°μ €κ°€ 인식할 수 μžˆλŠ” ν˜•νƒœμ˜ 파일둜 λ³€ν™˜ν•΄μ£ΌλŠ” μ›ΉνŒ©(webpack)μ΄λ‚˜ Browserify와 같은 도ꡬ가 ν•„μš”ν•˜λ‹€. μ›ΉνŒ©μ€ μ›Ή μ•±μ˜ μžμ›(HTML, CSS, 이미지)듀을 μžλ°”μŠ€ν¬λ¦½νŠΈ λͺ¨λ“ˆλ‘œ λ³€ν™˜ν•΄ ν•˜λ‚˜λ‘œ λ¬Άμ–΄ μ›Ή μ„±λŠ₯을 ν–₯μƒμ‹œμΌœ μ£ΌλŠ” μžλ°”μŠ€ν¬λ¦½νŠΈ λͺ¨λ“ˆ λ²ˆλ“€λŸ¬μ΄λ‹€. λ·° κ°œλ°œμžλ“€μ΄ νŽΈν•˜κ²Œ ν”„λ‘œμ νŠΈλ₯Ό ꡬ성할 수 μžˆλ„λ‘ CLI(Command Line Interface) 도ꡬλ₯Ό μ œκ³΅ν•œλ‹€.

μ‹œμž‘ν•˜κΈ°

$ vue create <project_name>
Vue CLI v3.11.0
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Update available: 4.0.4  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
? Please pick a preset: (Use arrow keys)
❯ default (babel, eslint)
  Manually select features

μ—¬κΈ°μ„œ defaultλ₯Ό μ„ νƒν•˜μ—¬ μƒμ„±ν•˜κ²Œ 되면 babelκ³Ό eslintκ°€ μ„€μΉ˜λœλ‹€. Manually select featuresλ₯Ό μ„ νƒν•˜κ²Œ 되면 μ•„λž˜μ™€ 같이 vuex, vue-router λ“± λͺ‡κ°€μ§€λ₯Ό 더 선택할 수 μžˆλ‹€.

? Please pick a preset: Manually select features
? Check the features needed for your project: (Press <space> to select, <a> to t
oggle all, <i> to invert selection)
❯◉ Babel
 β—― TypeScript
 β—― Progressive Web App (PWA) Support
 β—― Router
 β—― Vuex
 β—― CSS Pre-processors
 β—‰ Linter / Formatter
 β—― Unit Testing
 β—― E2E Testing

ν”„λ‘œμ νŠΈλ₯Ό ν•˜λ‹€κ°€ μΆ”κ°€μ μœΌλ‘œ plugin을 μ„€μΉ˜ν•˜κ³  싢은 κ²½μš°μ—λŠ” addλ₯Ό 톡해 ν•  수 μžˆλ‹€.

default λͺ¨λ“œλ₯Ό 선택해 μ„€μΉ˜ν•˜κ²Œλ˜λ©΄ λ‹€μŒκ³Ό 같은 ꡬ쑰둜 ν”„λ‘œμ νŠΈκ°€ μƒμ„±λœλ‹€.

.node_modules/
public/
        favicon.ico
        index.html
src/
    assets/
        logo.png
    components/
        HelloWorld.vue
    App.vue
    main.js
.gitignore
babel.config.js
package-lock.json
package.json
README.md

μ»΄ν¬λ„ŒνŠΈ 같은 κ²½μš°μ—λŠ” src/components ν΄λ”μ—μ„œ κ΄€λ¦¬ν•œλ‹€. μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 규λͺ¨κ°€ μ»€μ Έμ„œ κΈ°λŠ₯λ³„λ‘œ 관리λ₯Ό ν•΄μ•Όν•˜λŠ” κ²½μš°μ—λŠ” components/κΈ°λŠ₯/<μ»΄ν¬λ„ŒνŠΈλͺ…>.vue (components/login/LoginForm.vue)와 같은 ν˜•μ‹μœΌλ‘œ κ΄€λ¦¬ν•˜λŠ” 것이 μ’‹λ‹€.

$ vue add <plugin>

예λ₯Ό λ“€μ–΄μ„œ axios ν”ŒλŸ¬κ·ΈμΈμ„ μ„€μΉ˜ν•΄λ³Όκ²ƒμ΄λ‹€.

$ vue add axios
πŸ“¦  Installing vue-cli-plugin-axios...

+ vue-cli-plugin-axios@0.0.4
added 1 package from 1 contributor in 4.648s
βœ”  Successfully installed plugin: vue-cli-plugin-axios


πŸš€  Invoking generator for vue-cli-plugin-axios...
πŸ“¦  Installing additional dependencies...

added 5 packages from 8 contributors in 5.059s
βš“  Running completion hooks...

βœ”  Successfully invoked generator for plugin: vue-cli-plugin-axios
   The following files have been updated / added:

     src/plugins/axios.js
     package-lock.json
     package.json
     src/main.js

   You should review these changes with git diff and commit them.

axios ν”ŒλŸ¬κ·ΈμΈμ΄ μ„€μΉ˜λ˜κ³  λ‚œ ν›„ μˆ˜μ •λœ 파일과 μƒˆλ‘œ μΆ”κ°€λœ νŒŒμΌμ„ 확인할 수 μžˆλ‹€.

μ›ΉνŒ© μ„€μ • 파일

vue-cli 3.x μ—μ„œλŠ” μ›ΉνŒ© μ„€μ •νŒŒμΌμ„ λ…ΈμΆœν•˜μ§€ μ•ŠλŠ”λ‹€. 3.xμ—μ„œλŠ” 섀정을 μΆ”κ°€ν•˜κΈ° μœ„ν•΄μ„œλŠ” root 디렉토리에 vue.config.js νŒŒμΌμ„ μ„€μ •ν•˜κ³  λ‚΄μš©μ„ μž‘μ„±ν•΄μ€€λ‹€.

// vue.config.js
module.exports = {
  // 여기에 μ˜΅μ…˜μ„ μž‘μ„±ν•΄μ€€λ‹€.
}

vue ui

Vue-CLI3 UIλ₯Ό ν†΅ν•΄μ„œ ν”„λ‘œμ νŠΈλ₯Ό 관리할 수 μžˆλ‹€.

$ vue ui

μœ„μ™€ 같이 μ‹€ν–‰ν•˜λ©΄ ν”„λ‘œμ νŠΈ λ§€λ‹ˆμ €κ°€ localhost:8000으둜 λΈŒλΌμš°μ €λ₯Ό μ‹€ν–‰μ‹œν‚¨λ‹€. 이 ν”„λ‘œμ νŠΈ λ§€λ‹ˆμ € μœ„μ— ν”„λ‘œμ νŠΈλ₯Ό 생성할 수 있으며, 이미 μƒμ„±λœ ν”„λ‘œμ νŠΈλ₯Ό λΆˆλŸ¬μ™€μ„œ 관리 포인트둜 λ‘˜ 수 μžˆλ‹€.

ν”„λ‘œμ νŠΈ μ‹€ν–‰

$ npm run serve

build

μƒμš© 배포λ₯Ό μœ„ν•œ λΉŒλ“œλ₯Ό 진행할 수 μžˆλ‹€.

$ npm run build

λΉŒλ“œλ₯Ό μ‹€ν–‰ν•˜λ©΄ Vue CLIκ°€ μ›ΉνŒ©μ„ 톡해 ν”„λ‘œμ νŠΈμ˜ λͺ¨λ“  μ†ŒμŠ€ νŒŒμΌλ“€μ„ λ²ˆλ“€λ§ν•˜μ—¬ dist 디렉토리에 λ„£μ–΄μ€€λ‹€. dist 디렉토리λ₯Ό 확인해보면 μ›ΉνŒ©μ΄ λ²ˆλ“€λ§ν•œ νŒŒμΌλ“€μ„ 확인할 수 μžˆλ‹€. 이 νŒŒμΌλ“€μ€ μƒμš© 배포에 μ ν•©ν•˜λ„λ‘ μ›ΉνŒ©μ΄ μ΅œμ ν™” 해놓은 것이닀.

μ°Έμ‘°

Last updated