<!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>父子组件的数据传递</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <counter @change='Add' :count='0'></counter> <counter @change='Add' :count='0'></counter> <hr> <h3>总数:{{total}}</h3> </div> <script> var counter = { props:['count'], data:function(){ return { number:this.count } }, template:'<div @click="AddCount">{{number}}</div>', methods: { AddCount:function(){ this.number++; this.$emit('change',1) } }, } var app = new Vue({ el:'#app', data:{ total:0 }, methods: { Add:function(step){ console.log(step); // this.total= res++; this.total +=step; } }, components:{ counter:counter } }) </script> </body> </html>