首页 > 其他 > 详细

Vue子组件和根组件的关系

时间:2019-08-30 14:30:14      阅读:91      评论:0      收藏:0      [点我收藏+]
  • 代码:
<script type="text/javascript">
    const Foo = Vue.extend({
        template: `<div id="testzy">
            <div @click="change">test</div>
        </div>`,
        mounted: function() {
            debugger;
        },
        methods: {
            change() {
                debugger;
            },
        }
    });


    const routes = [{
        path: '/foo/:id',
        component: Foo
    }]


    const router = new VueRouter({
        routes // (缩写)相当于 routes: routes
    })

    const app = new Vue({
        data: {
            message: 'father',
            msg1: "hello",
            show: true
        },
        router, // (缩写)相当于 router: router
        mounted: function() {
            debugger;
            alert(this.$data.message);
        },

    }).$mount('#app')
</script>
  • app是Vue对象,也是一个组件,是最上层的根组件,Foo是VueComponent,是根组件里的子组件
  • 运行起来后,app对象里面会有一个叫children的数组,这个数组里面包含了Foo
  • 运行起来后,app和Foo里面都会有一些内置的属性和方法,比如$data,$el,$router等

Vue子组件和根组件的关系

原文:https://www.cnblogs.com/cowboybusy/p/11434601.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!