1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| <body> <div id="app"> <temp1 @func='console'></temp1> </div> <template id="temp1"> <div> 这是子组件 <button @click="dd(data)">点击打印</button> </div> </template> </body> <script> let temp1={ template:'#temp1', data() { return { data:{ age:188888, name:'zz' } } }, methods: { dd(e){ this.$emit('func',this.data) } }, }
let vm = new Vue({ el: '#app', data: { }, methods: { console(data){ console.log("打印了父组件的方法"+data.age); this.obj=data; console.log(this.obj); console.log(vm); } }, components:{ temp1, } }) </script>
|