Use ranuras en Vue (4-6)

Usar ranuras en Vue

De hecho, los dos están unidos, ¡eso es todo!

<!DOCTYPE html>
<html lang="en">
<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">
    <title>Document</title>
    <script src='./vue.js'></script>
</head>
<body>
   
    <div id="root">
        <body-content>
            <div class='header' slot='header'>header</div>
            <div class='footer' slot='footer'>footer</div>
        </body-content>
    </div>    
   
   
   <script>
       
        Vue.component('body-content', {
     
     
           template: `<div>
                         <slot name='header'>
                            <h1>default header</h1>
                         </slot>
                         <div class='content'>content</div>
                         <slot name='footer'></slot>
                      </div>`
        })

        var vm = new Vue({
     
     
            el: '#root'
        })
    </script>
</body>
</html>

Supongo que te gusta

Origin blog.csdn.net/weixin_45647118/article/details/114000254
Recomendado
Clasificación