<!DOCTYPE html> <html lang="zh"> <head> <title></title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://unpkg.com/vue/dist/vue.js"></script> <link href="../css/style.css" rel="stylesheet"> </head> <body> <div id="myApp"> <nba-all-stars c="奥尼尔" pf="加内特"> <span slot="sf">皮尔斯</span> <span slot="sg">雷阿伦</span> <span slot="pg">隆多</span> </nba-all-stars> </div> <script> Vue.component('nba-all-stars', { props: ['c', 'pf'], template: '<div>' + '<div>中锋:{{c}}</div>' + '<div>大前:{{pf}}</div>' + '<div>小前:<slot name="sf"></slot></div>' + '<div>分卫:<slot name="sg"></slot></div>' + '<div>控卫:<slot name="pg"></slot></div>' + '</div>', }); var myApp = new Vue({ el: '#myApp', }); </script> </body> </html>