Vue Code Style

July 16, 2021

๐Ÿ“– ๋“ค์–ด๊ฐ€๊ธฐ

Vue.js ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์กฐ๊ธˆ๋” ๊น”๋”ํ•˜๊ณ  ์ œ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ Vue API์—์„œ ์ œ๊ณตํ•˜๋Š” ์ฝ”๋“œ ์Šคํƒ€์ผ์„ ํ•ด์„ํ•ด์„œ ๊ธฐ๋กํ•˜๋ฉด ๊ณต๋ถ€ํ•ด๋ณผ ์˜ˆ์ •์ด๋‹ค.

ํ•„์ˆ˜์ ์œผ๋กœ ์ง€์ผœ์ค˜์•ผํ•˜๋Š” ๊ฒƒ๋“ค๊ณผ ๋งค์šฐ์ถ”์ฒœ, ์ถ”์ฒœ, ์ฃผ์˜ ์ •๋„์˜ ๊ฐ•๋„๋กœ ์š”๊ตฌ๋œ๋‹ค.

ํ•„์ˆ˜ ๊ทœ์น™

์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์— ํ•ฉ์„ฑ์–ด ์‚ฌ์šฉ

Vue์—์„œ ์ œ๊ณต๋˜๋Š” ๋นŒํŠธ์ธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ์™ธํ•˜๊ณ  ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์€ ํ•ญ์ƒ ํ•ฉ์„ฑ์–ด๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

  • ๋ชจ๋“  HTML ์—˜๋ฆฌ๋จผํŠธ์˜ ์ด๋ฆ„์€ ํ•œ ๋‹จ์–ด์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ฉ์„ฑ์–ด๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ถฉ๋Œ์„ ๋ฐฉ์ง€ํ•œ๋‹ค.

์ปดํฌ๋„ŒํŠธ ๋ฐ์ดํ„ฐ

์ปดํฌ๋„ŒํŠธ์˜ data๋Š” ๋ฐ˜๋“œ์‹œ ํ•จ์ˆ˜์—ฌ์•ผ ํ•œ๋‹ค.

  • data์˜ ๊ฐ’์ด ์˜ค๋ธŒ์ ํŠธ์ผ ๊ฒฝ์šฐ, ์ปดํฌ๋„ŒํŠธ์˜ ๋ชจ๋“  ์ธ์Šคํ„ด์Šค๊ฐ€ ๊ณต์œ ๋œ๋‹ค. ์ด๋ง์€์ฆ‰์Šจ ๋‹ค๋ฅธ ๊ณณ์—์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์žฌ์‚ฌ์šฉํ•œ๋‹ค๋ฉด data๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋ฏ€๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ณ€๊ฒฝ๋œ๋‹ค๋Š” ๋œป์ด๋‹ค.
    ๊ฐ ์ปดํฌ๋„ŒํŠธ๋Š” ์ž์ฒด data๋งŒ์„ ๊ด€๋ฆฌํ•˜๊ธฐ๋ฅผ ์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ณ ์œ ํ•œ data ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด์•ผ ํ•œ๋‹ค.

Props ์ •์˜

Prop์€ ๊ฐ€๋Šฅํ•œ ์ƒ์„ธํ•˜๊ฒŒ ์ •์˜๋˜์–ด์•ผํ•œ๋‹ค.

  • ์ปดํฌ๋„ŒํŠธ์˜ API๋ฅผ ๋ฌธ์„œํ™”ํ•˜๋ฏ€๋กœ ์ปดํฌ๋„ŒํŠธ์˜ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ์‰ฝ๊ฒŒ ์•Œ ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ๋‹ค.
  • Vue๋Š” ํƒ€์ž…์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ๋‚ด์žฅ๋˜์–ด ์žˆ๋Š”๋ฐ ์ด๋ฅผ ์–ด๊ธฐ๋ฉด ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜์—ฌ ์ž ์žฌ์  ์˜ค๋ฅ˜๋ฅผ ๋ง‰์„ ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค€๋‹ค.

v-for์— key ์ง€์ •

v-for๋Š” key์™€ ํ•ญ์ƒ ํ•จ๊ป˜ ์‚ฌ์šฉ

  • ์—๋‹ˆ๋ฉ”์ด์…˜์˜ ๊ฐ์ฒด ๋ถˆ๋ณ€์„ฑ๊ณผ ๊ฐ™์€ ์˜ˆ์ธก ๊ฐ€๋Šฅํ•œ ํ–‰๋™์„ ์œ ์ง€ํ•˜๋Š”๊ฒƒ
    Vue๋Š” ๊ฐ€์ƒ DOM ๋ฐฉ์‹์„ ์ฒดํƒํ•˜๊ณ  ์žˆ์œผ๋ฉฐ ๊ฐ€๋Šฅํ•œ ์ ์€ DOM์„ ์›€์ง์—ฌ์„œ ๋ Œ๋”๋ง์„ ์ตœ์ ํ™”ํ•˜๋Š”๋ฐ key๊ฐ’์„ ์„ค์ •ํ•˜๋ฏ€๋กœ์จ Vue์˜ ์›€์ง์ž„์„ ์˜ˆ์ธก ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

v-if์™€ v-for๋ฅผ ๋™์‹œ์— ์‚ฌ์šฉํ•˜์ง€๋ง์ž

v-for๊ฐ€ ์‚ฌ์šฉ๋œ ์—˜๋ฆฌ๋จผํŠธ์— ์ ˆ๋Œ€ v-if๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ง์ž.

Bad

  • ๋ฆฌ์ŠคํŠธ ๋ชฉ๋ก์„ ํ•„ํ„ฐ๋งํ•˜๊ธฐ ์œ„ํ•ด์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.
<div v-for="user in users" v-if="user.isActive"></div>

์ด ๊ฒฝ์šฐ computed ์†์„ฑ์„ ์‚ฌ์šฉํ•ด์„œ ํ•„ํ„ฐ๋ง๋œ ๋ชฉ๋ก์œผ๋กœ ๋Œ€์ฒดํ•ด์„œ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

  • ๋ฆฌ์ŠคํŠธ์˜ ๋‚ด์šฉ์„ ์ˆจ๊ธฐ๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.
<div v-for="user in users" v-if="shouldShowUsers"></div>

์ด ๊ฒฝ์šฐ v-if๋ฅผ ์ปจํ…Œ์ด๋„ˆ ์—˜๋ฆฌ๋จผํŠธ๋กœ ์˜ฎ๊ฒจ ์‚ฌ์šฉํ•œ๋‹ค.

Good

  • ํ•„ํ„ฐ๋ง๋œ ๋ชฉ๋ก์€ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ๊ณ„์‚ฐ๋˜๋ฏ€๋กœ ํ•„ํ„ฐ๋ง ํšจ์œจ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.
  • v-for="user in activeUsers"๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ Œ๋”๋ง ์ค‘์— ํ™œ์„ฑ ์‚ฌ์šฉ์ž๋งŒ ๋ฐ˜๋ณต๋˜๋ฏ€๋กœ ๋ Œ๋”๋ง ํšจ์œจ์„ฑ์ด ์ฆ๊ฐ€ํ•œ๋‹ค.
  • ๋กœ์ง์ด ๊ณ„์ธต์—์„œ ๋ถ„๋ฆฌ๋˜๋ฏ€๋กœ ์œ ์ง€ ๊ด€๋ฆฌ(ํ™•์žฅ์„ฑ)์ด ์‰ฌ์›Œ์ง„๋‹ค.

์ปดํฌ๋„ŒํŠธ ์Šคํƒ€์ผ ์Šค์ฝ”ํ”„

์ตœ์ƒ์œ„ APP ๊ตฌ์„ฑ ์š”์†Œ์™€ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ ์š”์†Œ์˜ ์Šคํƒ€์ผ์ด ์ „์—ญ์ ์ผ ์ˆ˜ ์žˆ์ง€๋งŒ ๋‹ค๋ฅธ ๊ตฌ์„ฑ์˜ ์ปดํฌ๋„ŒํŠธ์˜ ๊ฒฝ์šฐ ๋ฒ”์œ„๋Š” ํ•ญ์ƒ ์ง€์ •๋˜์–ด์•ผ ํ•œ๋‹ค.

์‹ฑ๊ธ€ ํŒŒ์ผ ์ปดํฌ๋„ŒํŠธ์˜ ๊ฒฝ์šฐ style์˜์—ญ์— scoped๋ฅผ ์†์„ฑ์„ ํ†ตํ•ด ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๋„๋ก ์Šคํƒ€์ผ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ๋Œ€ํ˜• ํ”„๋กœ์ ํŠธ๋‚˜ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž์™€ ํ•จ๊ป˜ ์ž‘์—…ํ•  ๋•Œ scoped ์„ค์ •์€ ์Šคํƒ€์ผ์˜ ์ถฉ๋Œ์„ ์ตœ์†Œํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค.

Private ์†์„ฑ ์ด๋ฆ„

ํ”Œ๋Ÿฌ๊ทธ์ธ, mixin ๋“ฑ์—์„œ ์ปค์Šคํ…€ ์‚ฌ์šฉ์ž private ํ”„๋กœํผํ‹ฐ๋Š” ํ•ญ์ƒ ์ ‘๋‘์‚ฌ $_๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅ.
๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ์™€ ์ถฉ๋Œ์„ ํ”ผํ•˜๋ ค๋ฉด named scope๋ฅผ ์‚ฌ์šฉ.

Vue ์—์„œ๋Š” ์ ‘๋‘์‚ฌ๋กœ _์™€ $๋ฅผ ์‚ฌ์šฉ์ค‘์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ํ˜ผํ•ฉํ•œ $_๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ private ์†์„ฑ์„ ๊ตฌ๋ถ„ํ•˜๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

var myGreatMixin = {
  // ...
  methods: {
    $_myGreatMixin_update: function () {
      // ...
    },
  },
}
// Even better!
var myGreatMixin = {
  // ...
  methods: {
    publicMethod() {
      // ...
      myPrivateFunction()
    },
  },
}

function myPrivateFunction() {
  // ...
}

export default myGreatMixin

๋งค์šฐ ์ถ”์ฒœํ•จ (๊ฐ€๋…์„ฑ ํ–ฅ์ƒ์„ ์œ„ํ•จ)

์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ

์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ ํŒŒ์ผ ์‹œ์Šคํ…œ ํ™˜๊ฒฝ์˜ ์—ฐ๊ฒฐ์„ ์‰ฝ๊ฒŒํ•˜๊ณ  ๋น ๋ฅด๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

Bad

Vue.component('TodoList', {
  // ...
})
Vue.component('TodoItem', {
  // ...
})

Good

components/
|- TodoList.vue
|- TodoItem.vue

์‹ฑ๊ธ€ ํŒŒ์ผ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„ ๊ทœ์น™ ์ง€์ •(casing)

์‹ฑ๊ธ€ ํŒŒ์ผ ์ปดํฌ๋„ŒํŠธ์˜ ์ด๋ฆ„์„ ์ง€์ •ํ• ๋• PascalCase ๋˜๋Š” kebab-case์„ ์‚ฌ์šฉํ•œ๋‹ค.

๋ฒ ์ด์Šค ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„

๊ธฐ๋ณธ ์ปดํฌ๋„ŒํŠธ์— ์ปจ๋ฒค์…˜์œผ๋กœ prefix Base, App, V๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ๋ถ„ํ•œ๋‹ค. ์ปจ๋ฒค์…˜์„ ์ด์šฉํ•˜์—ฌ ์ „์—ญ ์ปดํฌ๋„ŒํŠธ๋กœ ๋“ฑ๋กํ•˜์—ฌ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค.

Example

components\
|- BaseButton.vue
|- BaseTable.vue
|- BaseIcon.vue
components\
|- AppButton.vue
|- AppTable.vue
|- AppIcon.vue

๋ฒ ์ด์Šค ์ปดํฌ๋„ŒํŠธ ์ „์—ญ ์ปดํฌ๋„ŒํŠธ๋กœ ๋“ฑ๋ก

// main.js
let requireComponent = require.context('./src/components', false, /^Base[A-Z].(vue|js|ts)$/)
requireComponent.keys().forEach(fileName => {
  let baseComponentConfig = requireComponent(fileName)
  baseComponentConfig = baseComponentConfig.default || baseComponentConfig
  let baseComponentName = baseComponentConfig.name || fileName.replace(/^.+\//, '').replace(/\.\w+$/, '')
  Vue.component(baseComponentName, baseComponentConfig)
})

์‹ฑ๊ธ€ ์ธ์Šคํ„ด์Šค ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„

์ธ์Šคํ„ด์Šค๊ฐ€ ํ•˜๋‚˜๋งŒ ์žˆ์–ด์•ผํ•˜๋Š” ๊ตฌ์„ฑ ์š”์†Œ์˜ ์ ‘๋‘์‚ฌThe๋กœ ์‹œ์ž‘ํ•œ๋‹ค. ํ•˜๋‚˜๋งŒ ์žˆ์Œ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.

  • ํ•œํŽ˜์ด์ง€๋‹น ํ•œ๋ฒˆ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ์š”์†Œ
  • props๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š” ์š”์†Œ
  • props๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•˜์ง€๋งŒ ํ•œ๋ฒˆ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์š”์†Œ

Bad

components/
|- Heading.vue
|- MySidebar.vue

Good

components/
|- TheHeading.vue
|- TheSidebar.vue

๊ฐ•ํ•œ ์—ฐ๊ด€์„ฑ์„ ๊ฐ€์ง„ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„

์ƒ์œ„ ๊ตฌ์„ฑ ์š”์†Œ์™€ ๊ธด๋ฐ€ํ•˜๊ฒŒ ์—ฐ๊ฒฐ๋œ ํ•˜์œ„ ๊ตฌ์„ฑ ์š”์†Œ๋Š” ์ƒ์œ„ ๊ตฌ์„ฑ ์š”์†Œ ์ด๋ฆ„์„ ์ ‘๋‘์‚ฌ๋กœ ํฌํ•จํ•ด์•ผํ•œ๋‹ค.

์˜ˆ์‹œ๋ฅผํ†ตํ•ด ์œ„๋ง์„ ํ’€์–ด๋ณด๋ฉด..
๋ณดํ†ต์€ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ๋ฅผ ํ• ๋• ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ƒ์œ„ ๊ตฌ์„ฑ ์š”์†Œ์˜ ์ด๋ฆ„์„ ๋”ด ๋””๋ ‰ํ† ๋ฆฌ์— ํ•˜์œ„ ๊ตฌ์„ฑ์š”์†Œ๋ฅผ ์ค‘์ฒฉํ•ด์„œ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค.

components/
|- TodoList/
  |- Item/
    |- index.vue
    |- Button.vue
  |- index.vue

or

components/
|- TodoList/
  |- Item/
    |- Button.vue
  |- Item.vue
|- TodoList.vue

ํ•˜์ง€๋งŒ ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์„ ์ถ”์ฒœํ•˜์ง€ ์•Š๋Š”๋‹ค.

  1. ๋น„์Šทํ•œ ์ด๋ฆ„์„ ๊ฐ€์ง„ ํŒŒ์ผ๋“ค์ด ๋งŽ์•„์ง€๋ฉฐ, ํŽธ์ง‘๊ธฐ์—์„œ ์‹ ์†ํ•œ ํŒŒ์ผ์ „ํ™˜์ด ๋ถˆํŽธํ•˜๋‹ค.
  2. ์ค‘์ฒฉ๋œ ์—ฌ๋Ÿฌ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋Š” ํŽธ์ง‘๊ธฐ์˜ ์‚ฌ์ด๋“œ๋ฐ”์˜ ๋Ž์Šค๋ฅผ ๋Š˜๋ฆฌ๊ณ  ๊ฒ€์ƒ‰์— ๋ถˆ๋ฆฌํ•˜๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ๊ตฌ์…ฉ์š”์†Œ์˜ ์ด๋ฆ„์— ๊ด€๊ณ„๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ๋ฒ•์„ ์ถ”์ฒœํ•˜๋Š”๋ฐ, ํŽธ์ง‘๊ธฐ์—์„œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ํŒŒ์ผ์„ ์•ŒํŒŒ๋ฒณ ์ˆœ์œผ๋กœ ๊ตฌ์„ฑํ•˜๋ฏ€๋กœ ๊ด€๋ จ ํŒŒ์ผ๋„ ๋ณด๊ด€ํ•˜๊ธฐ๋„ ํŽธ๋ฆฌํ•˜๋‹ค.

Bad

component/
|- TodoList.vue
|- TodoItem.vue
|- TodoButton.vue
components/
|- SearchSidebar.vue
|- NavigationForSearchSidebar.vue

Good

components/
|- TodoList.vue
|- TodoListItem.vue
|- TodoListItemButton.vue
components/
|- SearchSidebar.vue
|- SearchSidebarNavigation.vue

์‚ฌ์‹ค ์ด ๋ถ€๋ถ„์€ ์ทจํ–ฅ์ฐจ์ด๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” IDE๊ฐ€ ์–ผ๋งˆ๋‚˜ ์ง€์›ํ•˜๋Š”๊ฐ€์— ๋”ฐ๋ผ์„œ ๊ฐ€๋…์„ฑ์ด๋‚˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐพ๋Š” ์‰ฌ์›€ ์ •๋„๊ฐ€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ•˜์ง€๋งŒ ๋‚˜๋„ ๊ฐ™์€ ์ด์œ ๋กœ ๋ถˆํŽธํ•จ์„ ๋Š๋ผ๋˜์ฐจ๋ผ ์ถ”์ฒœํ•ด์ฃผ๋Š” ๋ฐฉ์‹์„ ์ด์šฉํ•ด์„œ ๊ฐœ๋ฐœ์— ์ ์šฉํ•ด๋ณผ๊นŒํ•œ๋‹ค.

์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์˜ ๋‹จ์–ด ์ˆœ์„œ ์ •๋ ฌ

๊ตฌ์„ฑ์š”์†Œ ์ด๋ฆ„์€ ์ตœ์ƒ์œ„ ์ˆ˜์ค€ ๋‹จ์–ด๋กœ ์‹œ์ž‘ํ•˜๊ณ  ์„ค๋ช… ๋‹จ์–ด๋กœ ๋๋‚ด์•ผํ•œ๋‹ค.

์œ„์—์„œ ์–ธ๊ธ‰ํ–ˆ๋˜ ๊ฐ•ํ•œ ์—ฐ๊ด€์„ฑ์„ ๊ฐ€์ง„ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ ์ถ”์ฒœ๋ฉ๋‹ˆ๋‹ค.

Bad

components/
|- ClearSearchButton.vue
|- ExcludeFromSearchInput.vue
|- LaunchOnStartupCheckbox.vue
|- RunSearchButton.vue
|- SearchInput.vue
|- TermsCheckbox.vue

Good

components/
|- SearchButtonClear.vue
|- SearchButtonRun.vue
|- SearchInputQuery.vue
|- SearchInputExcludeGlob.vue
|- SettingsCheckboxTerms.vue
|- SettingCheckboxLaunchOnStartup.vue

์…€ํ”„ ํด๋กœ์ง• ์ปดํฌ๋„ŒํŠธ

์ปจํ…์ธ ๊ฐ€ ์—†๋Š” ๊ตฌ์„ฑ ์š”์†Œ๋Š” ๋‹จ์ผ ํŒŒ์ผ ๊ตฌ์„ฑ ์š”์†Œ, ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ ๋ฐ JSX์—์„œ ์ž์ฒด ๋‹ซ์•„์•ผํ•œ๋‹ค. - ๊ทธ๋Ÿฌ๋‚˜ DOM ํ…œํ”Œ๋ฆฟ์€ ๋‹ซ์ง€ ์•Š๋Š”๋‹ค.

์ถ”๊ฐ€์ ์œผ๋กœ html ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ PascalCase๋„ ์ง€์›ํ•˜์ง€๋งŒ kebab-case๋กœ๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. html ํƒœ๊ทธ๋Š” ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„์ด ์—†๊ธฐ๋•Œ๋ฌธ์— ๊ฐœ์ธ์ ์œผ๋กœ๋Š” kebab-case๋ฅผ ์„ ํ˜ธํ•œ๋‹ค.

Good

<!-- In single-file components, string template, and JSX -->
<MyComponent />
<!-- In DOM templates -->
<my-component></my-component>

Prop ์ด๋ฆ„ ๊ทœ์น™ ์ง€์ •(casing)

prop ์ด๋ฆ„์€ ์„ ์–ธ ์ค‘์—์„œ ํ•ญ์ƒ camelCase๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค. ๋˜ HTML ํ…œํ”Œ๋ฆฟ ๋ฐ JSX์—์„œ๋Š” kebab-case๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

Good

props: {
  greetingText: String
}
<WelcomeMessage greeting-text="hi" />

๋‹ค์ค‘ ์†์„ฑ ์—˜๋ฆฌ๋จผํŠธ

์—ฌ๋Ÿฌ ์†์„ฑ์„ ๊ฐ€์ง„ ์š”์†Œ๋Š” ํ•œ์ค„์— ํ•˜๋‚˜์˜ ์†์„ฑ์„ ๊ฐ€์ง„ ์—ฌ๋Ÿฌ ์ค„๋กœ ํ™•์žฅ๋˜์–ด์•ผ ํ•œ๋‹ค.

Good

<img src="https://..." alt="Vue Logo" />

ํ…œํ”Œ๋ฆฟ์—์„œ ๋‹จ์ˆœํ•œ ํ‘œํ˜„์‹

๊ตฌ์„ฑ ์š”์†Œ ํ…œํ”Œ๋ฆฟ์—๋Š” ๋” ๋ณต์žกํ•œ ํ‘œํ˜„์‹์ด ๊ณ„์‚ฐ๋œ ์†์„ฑ(computed) ๋˜๋Š” ๋ฉ”์„œ๋“œ(method)๋กœ ๋ฆฌํŽ™ํ„ฐ๋ง๋œ๋‹จ์ˆœํ•œ ํ‘œํ˜„์‹๋งŒ ํฌํ•จํ•ด์•ผํ•œ๋‹ค.

๋‹จ์ˆœํ•œ ๊ณ„์‚ฐ๋œ ์†์„ฑ


์ฐธ๊ณ 

results matching ""

    No results matching ""