<div id="myPage"> <div>请输入你的名字:<input v-model="myname"></div> <br/> <say-hello :pname="myname"/> </div> <script> Vue.component('say-hello',{ props:['pname'], template:"<div>你好,<strong>{{pname}}</strong></div>", }); var myPage = new Vue({ el:'#myPage', data:{ myname:'张三' } }) </script>
效果展示: