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
Was this helpful?