vue父子间通信案列三($emit和prop用法)
2024-10-20 15:50:01
<!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>
最新文章
- IntellijIdea中常用的快捷键
- 关于 ES6箭头函数
- [itint5]两有序数组的中位数
- FileGeodatabase和PersonalGeodatabase与ArcSDEGeodatabase三种数据库比较.
- 使用ActionBar实现Tab导航(快速生成Tab样式)
- pl/sql 中F8执行单行sql
- List之Distinct()
- CSS 专业技巧
- shell流程控制--循环语句
- c语言的枚举(遍历枚举)与数据类型总结
- MongoDB之建立Windows和本地虚拟机的双向连接
- Ajax 简单的实例代码
- 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明
- WebApi中使用session
- linux 下安装 oracle
- k8s 集群中的etcd故障解决
- spring boot application.properties
- libpcap详解【转】
- python添加Windows环境变量
- FP真验货客户的成品和半成品编码部分没有带尾续,导致FP规划错误 IN_SALES_ORDER数据不带CZ
热门文章
- caioj 1204 Catalan数(模板)
- 紫书 习题8-9 UVa 1613 (dfs染色+图的性质)
- 国庆 day 2 下午
- 实验了一下对于struct引用的成员的改动
- 基于Masonry自己主动计算cell的高度
- (六)storm-kafka源代码走读之PartitionManager
- mongodb E11000 duplicate key error collection: index: _id_ dup key
- js控制textarea输入字符串的个数,鼠标按下抬起推断输入字符数
- matplotlib 可视化 —— 移动坐标轴(中心位置)
- 33.AngularJS 应用 angular.module定义应用 angular.controller控制应用