首页 > 代码库 > vuejs 父组件向子组件传递($broadcast()的用法)

vuejs 父组件向子组件传递($broadcast()的用法)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue-dmeo</title>
    <script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="page">
          <input type="text" v-model="mess">
         <button @click="clickChild">父向子传递</button>
        <hellow></hellow>
    </div>
    <script type="text/javascript" src="http://cdn.bootcss.com/vue/1.0.26/vue.js"></script>
    <script>
       var  handle= function(){
               var hellow = {
               	     template:"{{arr|json}}",
               	     data:function(){
               	     	return {
               	     		arr:[]
               	     	}
               	     },
               	     events:{
               	     	‘addNew‘:function(val){
               	     		this.arr.push(val);
               	     	}
               	     }
               }

               return new Vue({
                    el:"#page",
                    data:{
                       mess:‘‘
                    },
                    methods:{
                    	clickChild:function(){
                    		this.$broadcast(‘addNew‘,this.mess.trim());
                    		this.mess = ‘‘;
                    	}
                    },
                   components:{
                       hellow:hellow,
                    }
                })
       }()
       
    </script>
</body>
</html>

 

vuejs 父组件向子组件传递($broadcast()的用法)