<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <div ref="test">ref=test</div> <!-- 应用组件--> <test ref="a"></test> <test ref="b"></test> <div>父组件<span>{{count}}</span></div> <input type="button" value="test" @click="change"> </div> <script src="js/vue.js"></script> <script> Vue.component('test',{ template:'<div>子组件-<span @click="add">{{number}}</span></div>', data:function () { return{ number:0 } }, methods:{ add:function () { this.number++ } } }) new Vue({ el:'#app', data:{ count:0 }, methods:{ // change:function () { // this.$refs.test.innerText='已经被修改' // refs获取到当前页面所有用到ref的标签,所以可以修改值 // } change:function () { // console.log(this.$refs.a.number) // console.log(this.$refs.b.number) this.count= this.$refs.a.number+this.$refs.b.number } } }) </script> </body> </html>