组合slot.html 983 B

1234567891011121314151617181920212223242526272829303132333435
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <link href="../css/style.css" rel="stylesheet"> </head>
  9. <body>
  10. <div id="myApp">
  11. <nba-all-stars c="奥尼尔" pf="加内特">
  12. <span slot="sf">皮尔斯</span>
  13. <span slot="sg">雷阿伦</span>
  14. <span slot="pg">隆多</span>
  15. </nba-all-stars>
  16. </div>
  17. <script>
  18. Vue.component('nba-all-stars', {
  19. props: ['c', 'pf'],
  20. template: '<div>'
  21. + '<div>中锋:{{c}}</div>'
  22. + '<div>大前:{{pf}}</div>'
  23. + '<div>小前:<slot name="sf"></slot></div>'
  24. + '<div>分卫:<slot name="sg"></slot></div>'
  25. + '<div>控卫:<slot name="pg"></slot></div>'
  26. + '</div>',
  27. });
  28. var myApp = new Vue({
  29. el: '#myApp',
  30. });
  31. </script>
  32. </body>
  33. </html>