Vue Loader

https://vue-loader-v14.vuejs.org/kr/features/scoped-css.html

Scoped CSS

<style> ํƒœ๊ทธ๊ฐ€ scoped ์†์„ฑ์„ ๊ฐ€์ง€๊ณ ์žˆ์„ ๋•Œ, CSS๋Š” ํ˜„์žฌ ์ปดํฌ๋„ŒํŠธ์˜ ์—˜๋ฆฌ๋จผํŠธ์—๋งŒ ์ ์šฉ

scoped option

  • scoped option์€ ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์—๋งŒ ์˜ํ–ฅ์„ ์ค€๋‹ค

    • ํ•˜์ง€๋งŒ, class ์ง€์ •์€ ํ•ด์•ผํ•œ๋‹ค

      • ๊ทธ๋ ‡๊ฒŒ ํ•ด์•ผ ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค!

        • why?

          • browser ๊ฐ€ css select ๋ฅผ rendering ํ•˜๋Š” ๋ฐฉ์‹ ๋•Œ๋ฌธ์— class ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ์ „์ฒด๋ฅผ ํƒ์ƒ‰ํ•จ

Local style ๊ณผ global style

  • ํ•˜๋‚˜์˜ ์ปดํฌ๋„ŒํŠธ ์•ˆ์— scoped style๊ณผ ๊ทธ๋ ‡์ง€ ์•Š์€ style์„ ๋™์‹œ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค

    ex)

    <style>
    /* global styles */
    </style>
    
    <style scoped>
    /* local styles */
    </style>

Child component์˜ Root element

  • scoped ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ์˜ style์€ ์ž์‹ component์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค

    • ํ•˜์ง€๋งŒ!

      • ์ž์‹ component์˜ root node ๋Š” ์˜ํ–ฅ์„ ๋ฐ›๋Š”๋‹ค!

        • ์ž์‹ component์˜ root element๋ฅผ ๋ฐ”๊ฟˆ์œผ๋กœ์จ layout์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ๋ชฉ์ 

Deep Selectors

>>> Combinator

  • scoped style์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์ž์‹ component์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์น˜๋ ค๋ฉด >>> combinator ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค

    ex)

    <style scoped>
    .a >>> .b { /* ... */ }
    </style>

v-html ๊ณผ scoped style

  • v-html ์€ scoped style์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๋Š”๋‹ค

    • but, deep selector (ex. ๋ฐ”๋กœ ์œ„์—์„œ ๋ณธ >>> combinator) ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด style ํ•  ์ˆ˜ ์žˆ๋‹ค

+

v-html vs v-text

: innerHTML๊ณผ innerText์˜ ์ฐจ์ด ๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค!

lazy load ๋ž€?

  • component ๊ฐ€ ์“ฐ์ผ ๋•Œ์—๋งŒ call์„ ๋ณด๋‚ธ๋‹ค

    • ํ›จ์”ฌ ๊ฒฝ์ œ์ !

  • ๋น ๋ฅธ loading์ด ํ•„์š”ํ•  ๋•Œ ์‚ฌ์šฉ

  • ์ž˜ ์•ˆ๊ฐ€๋Š” ๊ณณ์€ lazy๋กœ ์„ค์ •ํ•˜์ž!

    • ex) ๊ณ ๊ฐ์„ผํ„ฐ

Last updated