<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>html</title>
    <link rel="stylesheet" href="http://unpkg.com/iview/dist/styles/iview.css">
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    <script src="http://unpkg.com/vue/dist/vue.js"></script>
    <script src="http://unpkg.com/iview/dist/iview.min.js"></script>
</head>
<body>
    <div id="page">
        <com-header></com-header>
        <h3>----------------</h3>
        <com-footer></com-footer>
        <h2>===============对话列表====================</h2>
        <ul v-if="dhList && dhList.length">
            <template v-for="(item,index) in dhList">
                <li><a @click="remove(index)">X</a>&nbsp;{{item}}</li>
            </template>
        </ul>
    </div>

    <script type="text/x-template" id="comHeaderTemplate">
        <div>
            <button @click="sendMess()">
                {{msg}}
            </button>
            <input type=="sendMess()">
        </div>
    </script>

    <script type="text/x-template" id="comFoooterTemplate">
        <div>
            <button @click="sendMess()" >
                {{msg}}
            </button>
            <input type=="sendMess()">
        </div>
    </script>
    <script>
        var pu = new Vue();
        var dhList = [];

        var comHeader = {
            template:'#comHeaderTemplate',
            data:function(){
                return {
                    msg:'header',
                    userMess:''
                }
            },
            methods:{
                sendMess:function(){
                    pu.$emit('mess',this.userMess);
                    this.userMess = '';
                }
            },
            mounted:function(){
                pu.$on('mess2',function(m2){
                    console.log("footer:"+m2)
                    dhList.push("footer:"+m2);
                })
            }
        }

        var comFooter = {
            template:'#comFoooterTemplate',
            data:function(){
                return {
                    msg:'footer',
                    userMess:''
                }
            },
            methods:{
                sendMess:function(){
                    pu.$emit('mess2',this.userMess);
                    this.userMess = '';
                }
            },
            mounted:function(){
                pu.$on('mess',function(m){
                    console.log("header:"+m);
                    dhList.push("header:"+m);
                })
            }
        }

        new Vue({
            el:'#page',
            data:{
                dhList:dhList
            },
            methods:{
                remove:function(index){
                    );
                }
            },
            components:{
                comHeader:comHeader,
                comFooter:comFooter
            }
        })
    </script>
</body>
</html>

vue2.0 兄弟组件数据传递方法的更多相关文章

  1. vue2.0 父子组件数据传递prop

    vue的一个核心概念就是组件,而组件实例的作用域是孤立的,所以组件之间是不能直接引用其他组件的数据的.极端点举例来说,就是可以在同一个项目中,每一个组件内都可以定义相同名称的数据. data () { ...

  2. vue2.0父子组件通信的方法

    vue2.0组件通信方法:props传值和emit监听.(.sync方法已经移除.详情请点击)(dispatch-和-broadcast方法也已经废弃) props方法传值:Props 现在只能单项传 ...

  3. vue教程3-05 vue组件数据传递、父子组件数据获取,slot,router路由

    vue教程3-05 vue组件数据传递 一.vue默认情况下,子组件也没法访问父组件数据 <!DOCTYPE html> <html lang="en"> ...

  4. vue.js+koa2项目实战(五)axios 及 vue2.0 子组件和父组件之间的传值

    axios 用法: 1.安装 npm install axios --save-dev 2.导入 import axios from 'axios'; 3.使用 axios.post(url,para ...

  5. React中父子组件数据传递

    Vue.js中父子组件数据传递:Props Down ,  Events Up Angular中父子组件数据传递:Props Down,  Events  Up React中父子组件数据传递:Prop ...

  6. 手把手教你撸个vue2.0弹窗组件

    手把手教你撸个vue2.0弹窗组件 在开始之前需要了解一下开发vue插件的前置知识,推荐先看一下vue官网的插件介绍 预览地址 http://haogewudi.me/kiko/inde... 源码地 ...

  7. Spring MVC 3.0 返回JSON数据的方法

    Spring MVC 3.0 返回JSON数据的方法1. 直接 PrintWriter 输出2. 使用 JSP 视图3. 使用Spring内置的支持// Spring MVC 配置<bean c ...

  8. Vue2.0父子组件之间和兄弟组件之间的数据交互

    熟悉了Vue.js的同级组件之间通信,写此文章,以便记录. Vue是一个轻量级的渐进式框架,对于它的一些特性和优点,请在官网上进行查看,不再赘述. 使用NPM及相关命令行工具初始化的Vue工程,目录结 ...

  9. vue2.0 父子组件通信 兄弟组件通信

    父组件是通过props属性给子组件通信的来看下代码: 父组件: <parent> <child :child-com="content"></chil ...

随机推荐

  1. netty底层是事件驱动的异步库 但是可以await或者sync(本质是future超时机制)同步返回 但是官方 Prefer addListener(GenericFutureListener) to await()

    io.netty.channel 摘自:https://netty.io/4.0/api/io/netty/channel/ChannelFuture.html Interface ChannelFu ...

  2. elasticsearch index 之 put mapping

    elasticsearch index 之 put mapping   mapping机制使得elasticsearch索引数据变的更加灵活,近乎于no schema.mapping可以在建立索引时设 ...

  3. zzuoj--10424--无聊的课(简单几何)

    10424: 无聊的课 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 81  Solved: 16 [Submit][Status][Web Boar ...

  4. Nginx访问VM虚拟机CentOS 7系统与本地Windows系统共享目录403

    用VMware安装了CentOS7系统,并搭建了Nginx,MySQL,PHP的web项目运行环境,为了方便Windows本地主机进行程序调试把Windows本地项目目录共享到了虚拟机CentOS中的 ...

  5. CAS算法

    /** * CAS(Compare-And-Swap)算法保证了数据的原子性 * CAS算法是硬件对于并发操作共享数据的支持 * CAS包含了3个操作数: * 内存值 V 看成两步 读取内存值为1步 ...

  6. mysql实战45讲 (三) 事务隔离:为什么你改了我还看不见 极客时间读书笔记

    提到事务,你肯定不陌生,和数据库打交道的时候,我们总是会用到事务.最经典的例子就是转账,你要给朋友小王转100块钱,而此时你的银行卡只有100块钱. 转账过程具体到程序里会有一系列的操作,比如查询余额 ...

  7. 将hexo的评论系统由gitment改为Valine

    title: 将hexo的评论系统由gitment改为Valine toc: false date: 2018-09-13 15:10:56 categories: methods tags: hex ...

  8. SparkSession - Spark SQL 的 入口

    SparkSession - Spark SQL 的 入口 翻译自:https://jaceklaskowski.gitbooks.io/mastering-apache-spark/content/ ...

  9. Avalon.js 实现列表

    <table border="0" cellpadding="0" cellspacing="0" class="tab1& ...

  10. Timer 的 schedule()方法

    1.timer.schedule(new MyTask(),long time1,long time2); 第一个参数是TimerTask类,使用者要继承该类,并实现run()方法,因为TimerTa ...