父调子 $refs (把父组件的数据传给子组件) 

<template>
<div id="app">
<input type="button" name="" id="" @click="parentCall" value="父调子" />
<hello ref="chil" />//hello组件
</div>
</template> <script>
import hello from './components/Hello'
export default {
name: 'app',
'components': {
hello
},
methods: {
   parentCall () {
     this.$refs.chil.chilFn('我是父元素传过来的')
   }
}
}
</script> /*Hello.vue :*/ <template>
<div class="hello"></div>
</template> <script>
export default {
name: 'hello',
'methods': {
   chilFn (msg) {
     alert(msg)
   }
}
}
</script>
子调父 $emit (把子组件的数据传给父组件)

ps:App.vue 父组件
  Hello.vue 子组件 <!--App.vue :--> <template>
  <div id="app">
    <hello @newNodeEvent="parentLisen" />
  </div>
</template> <script>
import hello from './components/Hello'
export default {
name: 'app',
'components': {
hello
},
methods: {
parentLisen(evtValue) {
//evtValue 是子组件传过来的值
alert(evtValue)
}
}
}
</script> <!--Hello.vue :--> <template>
  <div class="hello">
    <input type="button" name="" id="" @click="chilCall()" value="子调父" />
  </div>
</template> <script>
export default {
name: 'hello',
'methods': {
chilCall(pars) {
this.$emit('newNodeEvent', '我是子元素传过来的')
}
}
}
</script>

vue.js $refs和$emit 父子组件交互的更多相关文章

  1. vue的props和$emit / 父子组件通信

    props 父级: 父级组件中引用子组件,并将自己data下面的giveChild数据绑定在  giveChildData  传给子 <myChild :giveChildData=" ...

  2. 前端-Vue基础3(父子组件交互)

    1.子组件往父组件传值 点击子组件的值,子组件自增,父组件的值也跟着自增 通过:this.$emit('change')方法向父组件暴露事件,在子组件中引用,可以调用父组件的方法 点击子组件触发cli ...

  3. 在vue中使用setter改写父子组件传的值

    概述 最近在用muse ui的时候碰到一个问题,简单来说是这样的,父子之间传值,父组件和子组件使用相同的props命名,并且子组件不用emit,而用等号赋值. 最后使用计算属性的setter函数解决了 ...

  4. vue bus方式解决非父子组件间的传值

    对于非父子组件之间的传值 通常使用VUEX 和总线等方式解决 这里我聊聊发布订阅模式(总线) <body> <div class="app"> <ch ...

  5. vue中\$refs、\$emit、$on的使用场景

    1.$emit的使用场景 子组件调用父组件的方法并传递数据注意:子组件标签中的时间也不区分大小写要用“-”隔开 子组件: <template> <button @click=&quo ...

  6. 【前端vue开发】vue子调父 $emit (把子组件的数据传给父组件)

    ps:App.vue 父组件 Hello.vue 子组件 <!--App.vue :--> <template> <div id="app"> ...

  7. vue.js使用props在父子组件之间传参

    本篇文章是我参考官方文档整理的,供大家参考,高手勿喷! prop 组件实例的作用域是孤立的.这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,我们需要通过子 ...

  8. vue中$refs、,$emit、$on

    $emit https://blog.csdn.net/sllailcp/article/details/78595077 $on https://www.jianshu.com/p/a544728b ...

  9. vue:父子组件间通信,父组件调用子组件方法进行校验子组件的表单

    参考: ElementUI多个子组件表单的校验管理:https://www.jianshu.com/p/541d8b18cf95 Vue 子组件调用父组件方法总结:https://juejin.im/ ...

随机推荐

  1. [转]文件后缀与Mime类型对照表

    //文档文件类型的 .ai application/postscript .eps application/postscript .exe application/octet-stream .doc ...

  2. matplotlib01

    matplotlib是基于numpy的一套Python工具包.这个包提供了丰富的数据绘图工具,可实现数据分析的可视化. 所以在安装matplotlib时,需要先安装numpy包.

  3. C# 7 out variables, tuples & other new features

    C# 7 out variables, tuples & other new features C# 7 is available on new Visual Studio 2017 and ...

  4. vmware网络模式仅主机模式linux不能ping通window

    问题描述 vmware在使用仅主机模式,新建的linux虚拟机,不能ping通window本机(宿主主机).....(这不蛋疼吗...) 注意:后面的搞定后的结果 解决方案 开启家庭组的,网络发现功能 ...

  5. ssm(spring mvc+mybatis)+netty4开发qiq

    发布时间:2018-10-30   技术:spring mvc+mybatis+nett4+layui   概述 简单快捷的IM方案,快速打造在线IM,可用于公司内网.外网通讯,客服系统等,实现了so ...

  6. Pinpoint - 应用性能管理(APM)平台实践之部署篇

    0.0 前言 国内的APM行业这两年刚刚起步,但是在国外却比较成熟了,并且由于这两年人力成本的快速提高,国内外涌现了几家非常不错的APM企业,例如APPdynamic,Dynamic,NewRelic ...

  7. Web 进化

    来源于:http://xitu.github.io/2016/05/11/history-of-web/ 传统后台架构 上古时代 上古时代 123456789101112131415161718192 ...

  8. k8s oomkilled超出容器的内存限制

    超出容器的内存限制 只要节点有足够的内存资源,那容器就可以使用超过其申请的内存,但是不允许容器使用超过其限制的 资源.如果容器分配了超过限制的内存,这个容器将会被优先结束.如果容器持续使用超过限制的内 ...

  9. apache kafka系列之Producer处理逻辑

     最近研究producer的负载均衡策略,,,,我在librdkafka里边用代码实现了partition 值的轮询方法,,,但是在现场验证时,他的负载均衡不起作用,,,所以来找找原因: 下文是一篇描 ...

  10. nginx端合并JS

    转载于:http://www.tuicool.com/articles/IjMNnq 配置文件: location /static/css/ { concat on; concat_max_files ...