<body> <div id="app"> <cpn></cpn> </div> <template id="cpn"> <div> <ccpn></ccpn> <h3>我是子组件</h3> <button @click="btnClick">按钮</button> </div> </template> <template id="ccpn"> <div> <h3>我是子组件里面的子组件</h3> <button @click="ccpnClick">访问根组件</button> </div> </template> <script src='https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js'></script> <script> const app = new Vue({ el: '#app', data: { name: "我是根组件" }, components: { cpn: { template: "#cpn", data() { return { name: "我是第一个子组件" } }, methods: { btnClick() { // 访问父组件 .$parent console.log(this.$parent.name); } }, components: { ccpn: { template: "#ccpn", data() { return { name: "我的第二个子组件 也就是子组件里面的子组件" } }, methods: { ccpnClick() { // 访问根组件 .$root console.log(this.$root); } } } } } } }) </script> </body>