<!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. Android学习路线(十三)Activity生命周期——暂停和恢复(Pausing and Resuming )一个Activity

    在正常使用应用的过程中.前台的activity在一些时候会被其它的组件遮挡,导致这个activity暂停.举个样例.当一个半透明的activity被打开(比如一个dialog样式的activity), ...

  2. linux 终端提示符

    默认的当路径一长就难看得出奇. 我的设置: export PS1="|\W$>\[\e[0m\]" 最后效果就是|目录名$> 参考:https://www.cnblog ...

  3. TSNE——目前最好的降维方法

    转自:http://blog.csdn.net/u012162613/article/details/45920827 1.流形学习的概念 流形学习方法(Manifold Learning),简称流形 ...

  4. PJNATH介绍 -- 开源的用于NAT穿透的ICE, STUN和TURN

    原文地址:http://blog.pjsip.org/2007/04/06/introducing-pjnath-open-source-ice-stun-and-turn/ ICE是什么? 对于那些 ...

  5. POJ 1275 差分约束

    一堆化不等式,,,,,, 懒得写了... 请看mars_ch的blog-.. 戳戳戳戳戳 还是她给我找的错---. //By SiriusRen #include <queue> #inc ...

  6. (转)script标签到底该放在哪里

    一般script标签会被放在头部或尾部.头部就是<head>里面,尾部一般指<body>里[4-5]. 将script放在<head>里,浏览器解析HTML,发现s ...

  7. HTML、CSS规范

    作为一名前端开发者,至少要对HTML.CSS规范有个了解,然后尝试在项目是使用,以便别人阅读你代码的时候,也相对轻松点. HTML.CSS规范,参见:编码规范 by @mdo JavaScript 参 ...

  8. logging.config模块---使用配置文件管理logger

    logging配置文件 一.使用到的模块: logging.config 官方文档: https://docs.python.org/3/library/logging.config.html 非官方 ...

  9. mariadb数据库的链接查询和表格设计

    链接查询 练习准备: --创建学生表 create table students ( id int unsigned not null auto_increment primary key, name ...

  10. vue项目打包后想发布在apache www/vue 目录下

    使用的是vue-element-admin做示例,可以参考Vue项目根据不同运行环境打包项目,其他项目应该大同小异. 使用vue-router的browserHistory模式,配置mode: 'hi ...