๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[๊ฐœ๋ฐœ] Practice/Vue.js

[Vue.js] Blog ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ ๋ฐ Bootstrap ์‚ฌ์šฉํ•˜๊ธฐ

by Connecting-the-dots 2022. 4. 5.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ก ์‹ค์Šต ํฌ์ธํŠธ!

๐Ÿ’œ Blog ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ


๐Ÿ’œ Bootstrap ์„ค์น˜ํ•˜๊ธฐ

  • ์ด๋ฒˆ์—๋Š” vue ์—์„œ Bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•ด๋ณด์•˜๋‹ค.
  • Bootstrap ์€ ์›นํŽ˜์ด์ง€์— ํ•„์š”ํ•œ ๋ฒ„ํŠผ, ๋ฉ”๋‰ด, ์นด๋“œ, ๋ฆฌ์ŠคํŠธ ๋“ฑ์˜ ๋ ˆ์ด์•„์›ƒ์„ ์‰ฝ๊ฒŒ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌ-๋ถ™์—ฌ๋„ฃ๊ธฐํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.
  • Bootstrap ์„ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
    • css.js ํŒŒ์ผ์„ ๋ณต์‚ฌ-๋ถ™์—ฌ๋„ฃ๊ธฐํ•˜์—ฌ ์„ค์น˜ํ•˜๊ธฐ
    • ํ„ฐ๋ฏธ๋„์—์„œ npm ์„ ์ด์šฉํ•˜์—ฌ ์„ค์น˜ํ•˜๊ธฐ
    • BootstrapVue ๋ฅผ ์„ค์น˜ํ•˜๊ธฐ (Vue 2 ๋ฒ„์ „๋งŒ ํ˜ธํ™˜๋˜๋Š” ์  ์ฐธ๊ณ !)

 

๐Ÿค css.js ํŒŒ์ผ์„ ๋ณต์‚ฌ-๋ถ™์—ฌ๋„ฃ๊ธฐํ•˜์—ฌ Bootstrap ์„ค์น˜ํ•˜๊ธฐ

  • Bootstrap ์ด๋ผ๊ณ  ๊ตฌ๊ธ€์— ๊ฒ€์ƒ‰ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด ์‚ฌ์ดํŠธ๊ฐ€ ํ•˜๋‚˜ ๋‚˜์˜จ๋‹ค.

 

 

Bootstrap

The most popular HTML, CSS, and JS library in the world.

getbootstrap.com

  • ๊ท€์ฐฎ์œผ๋ฉด ์œ„ ๋งํฌ ํด๋ฆญํ•ด์„œ ๋“ค์–ด๊ฐ€์ž..ใ…Žใ…Ž

 

  • Get started ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์ค€๋‹ค.

 

  • ์ด์ œ ์œ„์™€ ๊ฐ™์ด ํ™”๋ฉด์ด ๋ณด์ด๋ฉด ์šฐ์ธก ์ƒ๋‹จ์—์„œ Bootstrap ๋ฒ„์ „์„ ์„ ํƒํ•ด์ค€ ๋‹ค์Œ, ์œ„์— ํ‘œ์‹œํ•œ CSS, JS ๋‘ ๊ณณ์˜ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ index.html ์— ๊ทธ๋Œ€๋กœ ๋ถ™์—ฌ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค.

 

<!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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <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 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
  </body>
</html>
  • ๋‚˜๋Š” ์œ„์™€ ๊ฐ™์ด CSS ์ฝ”๋“œ๋Š” <head></head> ์—, JS ์ฝ”๋“œ๋Š” <body></body> ์— ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.
  • JS ์ฝ”๋“œ๋Š” </body> ๋ฐ”๋กœ ์œ„์— ์ ์–ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

๐Ÿค ํ„ฐ๋ฏธ๋„์—์„œ npm ์„ ์ด์šฉํ•˜์—ฌ Bootstrap ์„ค์น˜ํ•˜๊ธฐ

  • npm ์œผ๋กœ Bootstrap ์„ ์„ค์น˜ํ•  ๊ฑฐ๋ฉด ๋จผ์ € ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ ํ›„, ์ƒ์„ฑ๋œ ํ”„๋กœ์ ํŠธ ํด๋”๋ฅผ VSCode ์—๋””ํ„ฐ๋กœ ์—ด์–ด์ค€ ํ›„ ์ง„ํ–‰ํ•ด์•ผ ํ•œ๋‹ค.
  • ํ˜น์‹œ, ํ„ฐ๋ฏธ๋„์—์„œ npm run serve ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ผœ๋‘” ๊ฒŒ ์žˆ๋‹ค๋ฉด, ๊ทธ ์ƒํƒœ์—์„œ Bootstrap ์„ค์น˜์‹œ ์ œ๋Œ€๋กœ ์„ค์น˜๊ฐ€ ์•ˆ ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ฐ˜๋“œ์‹œ ํ•ด๋‹น ํ”„๋กœ์„ธ์Šค๋ฅผ ์ข…๋ฃŒํ•œ ํ›„์— Bootstrap ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•˜์ž.

 

// Bootstrap 5 ๋ฒ„์ „ ์„ค์น˜ํ•˜๋Š” ๊ฒฝ์šฐ
npm install bootstrap

// Bootstrap 4 ๋ฒ„์ „ ์„ค์น˜ํ•˜๋Š” ๊ฒฝ์šฐ
npm install bootstrap@4 jquery popper.js
  • ์œ„ ์ฝ”๋“œ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•˜์—ฌ ํ„ฐ๋ฏธ๋„์— ์ž…๋ ฅํ•˜๋ฉด ์„ค์น˜๊ฐ€ ์ง„ํ–‰๋œ๋‹ค.
  • ์ฐธ๊ณ ๋กœ yarn ์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด npm install ๋Œ€์‹ ์— yarn add ๋ผ๊ณ  ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.
  • ์„ค์น˜ ๋ช…๋ น์–ด๋Š” ์–ธ์ œ๋“  ์ˆ˜์ •๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ Bootstrap ํ™ˆํŽ˜์ด์ง€์—์„œ ๋จผ์ € ํ™•์ธํ•˜๋Š” ๊ฒŒ ์ข‹๋‹ค.

 

import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
  • ์ด์ œ main.js ํŒŒ์ผ์˜ ๋งจ ๋งˆ์ง€๋ง‰์ค„๋ณด๋‹ค ์ƒ๋‹จ์— ์œ„ ๋‘ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

๐Ÿ’œ Bootstrap ์‚ฌ์šฉํ•˜๊ธฐ

  • Bootstrap ํ™ˆํŽ˜์ด์ง€์— ์ ‘์†ํ•˜์—ฌ ์›ํ•˜๋Š” UI ๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
  • button, navbar, card ๋“ฑ์„ ๊ฒ€์ƒ‰ํ•˜๋ฉด html ์ƒ˜ํ”Œ ์ฝ”๋“œ๊ฐ€ ๋‚˜์˜ค๋Š”๋ฐ, ์ด๊ฑธ ๋ณต์‚ฌํ•˜์—ฌ ๋‚ด ํ”„๋กœ์ ํŠธ์˜ ์›ํ•˜๋Š” ์œ„์น˜์— ๋ถ™์—ฌ๋„ฃ์–ด์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•