<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href=""> <script src="https://cdn.jsdelivr.net/npm/vue"></script> </head> <body> <template id='cpn'> <div> <h4 v-html="cmessage"></h4> <ul> <li v-for="item in cmovies"> {{item}} </li> </ul> </div> </template> <div id='app'> //分别绑定用哪个变量去接收哪个变量的值 <cpn :cmovies='movies' :cmessage='message' ></cpn> </div> <script> //子组件 const cpn = { //外部模板 template: '#cpn', //声明用这些变量去接收父组件的传值 props: ['cmovies', 'cmessage'], data() { return { } } } const vm = new Vue({ el: '#app', data: { message: '来看电影啊!<br/>这里是我从父组件拿来的电影数据!', movies: ['哪吒', '千与千寻', '哆啦A梦', '蜘蛛侠'] }, //注册子组件 components: { cpn } }) </script> </body> </html>