<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>js测试父子之间通信</title>
	<script type="text/javascript" src="lib/boot.js"></script>
	<style>
		.box{
			width:100%;
			max-width:640px;
			margin:40px auto;
			border:1px solid #ccc;
			padding:20px;
		}
	</style>
</head>
<body>
	<div id="app" v-cloak>
		<!-- 定义 -->
		<child :msg-data="msg"  @child-get="getList" @child-cancel="clearList">
			 <slot="cs-slot"></slot>
		</child>
	</div>
	<script>
		var tx = function(){
			// 父组件
			var child = {
				template:`
				     <div name="cs-slot">slot用法</div>
                     <div class="box">
						 <i-button @click="send">获取数据</i-button>
    					 <i-button @click="cancel" type="primary">取消数据</i-button>
    					 <div>
                             <ul>
                                 <li v-for="item in msgData">名称:{{item.name}}---id:{{item.id}}</li>
                             </ul>
    					 </div>
                     </div>
				`,
				props:['msgData'],//接收父传来的数据
                methods:{
                	send:function(){
                       // 发送给父的方法
                       this.$emit('child-get','hellow kitty')
                	},
                	cancel:function(){
                	   this.$emit('child-cancel','')
                	}
                }

			}
			return new Vue({
				el:'#app',
				data:{
					msg:[]
				},
				methods:{
                   getList:function(val){
                   	  console.log(val);
                   	  this.msg = [{name:'百度',id:'001'},{name:'百威',id:'002'},{name:'腾讯',id:'003'}];
                   },
                   clearList:function(){
                   	  this.msg = [];
                   }
				},
				components:{
					child:child
				}
			})
		}()
	</script>
</body>
</html>

  

最新文章

  1. IntellijIdea中常用的快捷键
  2. 关于 ES6箭头函数
  3. [itint5]两有序数组的中位数
  4. FileGeodatabase和PersonalGeodatabase与ArcSDEGeodatabase三种数据库比较.
  5. 使用ActionBar实现Tab导航(快速生成Tab样式)
  6. pl/sql 中F8执行单行sql
  7. List之Distinct()
  8. CSS 专业技巧
  9. shell流程控制--循环语句
  10. c语言的枚举(遍历枚举)与数据类型总结
  11. MongoDB之建立Windows和本地虚拟机的双向连接
  12. Ajax 简单的实例代码
  13. 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明
  14. WebApi中使用session
  15. linux 下安装 oracle
  16. k8s 集群中的etcd故障解决
  17. spring boot application.properties
  18. libpcap详解【转】
  19. python添加Windows环境变量
  20. FP真验货客户的成品和半成品编码部分没有带尾续,导致FP规划错误 IN_SALES_ORDER数据不带CZ

热门文章

  1. caioj 1204 Catalan数(模板)
  2. 紫书 习题8-9 UVa 1613 (dfs染色+图的性质)
  3. 国庆 day 2 下午
  4. 实验了一下对于struct引用的成员的改动
  5. 基于Masonry自己主动计算cell的高度
  6. (六)storm-kafka源代码走读之PartitionManager
  7. mongodb E11000 duplicate key error collection: index: _id_ dup key
  8. js控制textarea输入字符串的个数,鼠标按下抬起推断输入字符数
  9. matplotlib 可视化 —— 移动坐标轴(中心位置)
  10. 33.AngularJS 应用 angular.module定义应用 angular.controller控制应用