λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
JavaScript/Vue

Named View

by μ½”λ”©ν•˜λŠ” λΆ•μ–΄ 2022. 6. 6.
λ°˜μ‘ν˜•

Named View(λ„€μž„λ“œ λ·°)λŠ” νŠΉμ • νŽ˜μ΄μ§€λ‘œ μ΄λ™ν–ˆμ„ λ•Œ μ—¬λŸ¬ 개의 μ»΄ν¬λ„ŒνŠΈλ₯Ό λ™μ‹œμ— ν‘œμ‹œν•˜λŠ” λΌμš°νŒ… 방식이닀.

λ„€μž„λ“œ λ·°λŠ” 같은 λ ˆλ²¨μ—μ„œ μ—¬λŸ¬ 개의 μ»΄ν¬λ„ŒνŠΈλ₯Ό ν•œ λ²ˆμ— ν‘œμ‹œν•œλ‹€.

 

<!DOCTYPE html>
<head>
  <title>Vue Named View Sample</title>
</head>
<body>
  <div id="app">
    <router-view name="header"></router-view>
    <router-view></router-view>
    <router-view name="footer"></router-view>
  </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router@3.0.1/dist/vue-router.js"></script>
  <script>
    var Body = { template: `<div>This is Body</div>` }
    var Header = { template: `<div>This is Header</div>` }
    var Footer = { template: `<div>This is Footer</div>` }

    var router = new VueRouter({
      routes: [
        { 
          path: '/', 
          components: {
            default: Body,
            header: Header,
            footer: Footer,
          } 
        }
      ] 
    })

    var app = new Vue({
      router
    }).$mount('#app')
  </script>
</body>
</html>

 

 

λ°˜μ‘ν˜•

'JavaScript > Vue' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

[Vue.js] Vueμ—μ„œμ˜ μžλ°”μŠ€ν¬λ¦½νŠΈ ν‘œν˜„μ‹  (0) 2022.06.06
[Vue.js] v-bind  (0) 2022.06.06
Nested Router  (0) 2022.06.06
[Vue.js] router URL의 ν•΄μ‹œ κ°’(#)을 μ—†μ• λŠ” 법  (0) 2022.06.06
Vue router  (0) 2022.06.06

λŒ“κΈ€