<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="app"> <div :style='{fontSize:fontSize+"px"}'>{{pmsg}}</div> <menu-item :parr='parr' @enlarge-text='handle'></menu-item> </div> <script type="text/javascript" src="./js/vue.js"></script> <script> Vue.component('menu-item', { props: ['parr'], template: `<div>><ul><li :key="index" v-for="(item,index) in parr">{{item}}</li></ul> <button @click='parr.push("lemon")'>点击</button> <button @click='$emit("enlarge-text")'>扩大</button> </div>` }); var vm = new Vue({ el: '#app', data: { pmsg: '父亲组件内容', pstr: 'hello', parr: ['apple', 'orange', 'banana'], fontSize: 10 }, methods: { handle: function() { this.fontSize += 10; } } }) </script> </body> </html>