首页 > 其他 > 详细

vue动态加载组件通过 Prop 向子组件传递数据

时间:2021-06-08 13:38:34      阅读:24      评论:0      收藏:0      [点我收藏+]
<div id="app">
    <button onclick="load">动态加载组件</button>
    <component v-bind:is="currentTabComponent" :message="message"></component>
</div>
 
<script>
// 注册
Vue.component(child, {
  // 声明 props
  props: [message],
  // 同样也可以在 vm 实例中像 “this.message” 这样使用
  template: <span>{{ message }}</span>
})
// 创建根实例
new Vue({
    el: #app,
    data:function(){
        return {
            currentTabComponent:null,
            message:hello!
        }
    },
    methods:{
        load:function(){
            this.currentTabComponent = child;
        }
    },
  
})
</script>

 

vue动态加载组件通过 Prop 向子组件传递数据

原文:https://www.cnblogs.com/wishit/p/14861369.html

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