本文基于以下的代码进行修改:
<script src="https://cdn.uv.cc/vue/2.6.10/vue.min.js"></script> <div id="app"> <child :root="{ mode: 'edit', top: get_this(), }" msg="hello!"></child> </div> <script> // 这会注册一个全局组件 Vue.component('child', { // 声明 props props: ['msg', 'root'], created() { this.root.top.fgh() }, // prop 可以用在模板内 // 可以用 `this.msg` 设置 template: '<span>{{ msg }}</span>' }) new Vue({ el: '#app', data: { text: 56789 }, methods: { get_this() { return this }, fgh() { console.log(68, this.text) } } }) </script>