<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id ="app"> <!--将根模板中变量中数据赋值给将子模版props中定义的变量 --> <cpn :cmovies="movies" :cmessage="message"></cpn> </div> <template id="cpn"> <div> <ul> <!-- 模板中使用 --> <li v-for="item in cmovies" > {{item}} </li> </ul> <h2>{{cmessage}}</h2> </div> </template> <script type="text/javascript" src="../js/vue.js"></script> <script> const cpn = { template:'#cpn', props:{ cmovies:{ type:Array }, cmessage:{ type:String } } } const vm = new Vue({ el: '#app', data: { movies:['傲慢与偏见','海蒂与爷爷','千与千寻'], message:'hello' }, components:{ cpn }, computed: { }, methods: { } }); </script> </body> </html>