vue.js $refs和$emit 父子组件交互
父调子 $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 父子组件交互的更多相关文章
- vue的props和$emit / 父子组件通信
props 父级: 父级组件中引用子组件,并将自己data下面的giveChild数据绑定在 giveChildData 传给子 <myChild :giveChildData=" ...
- 前端-Vue基础3(父子组件交互)
1.子组件往父组件传值 点击子组件的值,子组件自增,父组件的值也跟着自增 通过:this.$emit('change')方法向父组件暴露事件,在子组件中引用,可以调用父组件的方法 点击子组件触发cli ...
- 在vue中使用setter改写父子组件传的值
概述 最近在用muse ui的时候碰到一个问题,简单来说是这样的,父子之间传值,父组件和子组件使用相同的props命名,并且子组件不用emit,而用等号赋值. 最后使用计算属性的setter函数解决了 ...
- vue bus方式解决非父子组件间的传值
对于非父子组件之间的传值 通常使用VUEX 和总线等方式解决 这里我聊聊发布订阅模式(总线) <body> <div class="app"> <ch ...
- vue中\$refs、\$emit、$on的使用场景
1.$emit的使用场景 子组件调用父组件的方法并传递数据注意:子组件标签中的时间也不区分大小写要用“-”隔开 子组件: <template> <button @click=&quo ...
- 【前端vue开发】vue子调父 $emit (把子组件的数据传给父组件)
ps:App.vue 父组件 Hello.vue 子组件 <!--App.vue :--> <template> <div id="app"> ...
- vue.js使用props在父子组件之间传参
本篇文章是我参考官方文档整理的,供大家参考,高手勿喷! prop 组件实例的作用域是孤立的.这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,我们需要通过子 ...
- vue中$refs、,$emit、$on
$emit https://blog.csdn.net/sllailcp/article/details/78595077 $on https://www.jianshu.com/p/a544728b ...
- vue:父子组件间通信,父组件调用子组件方法进行校验子组件的表单
参考: ElementUI多个子组件表单的校验管理:https://www.jianshu.com/p/541d8b18cf95 Vue 子组件调用父组件方法总结:https://juejin.im/ ...
随机推荐
- Solidworks机构运动仿真
使用Solidworks Motion插件可以对机构进行运动学/动力学仿真.机构约束添加完成后,可以在主动部件(关节)处添加马达进行驱动.运动可以是简单的匀速运动或者复杂的表达式.数据点形式的运动. ...
- SQL Manager Lite可视化工具部分中英对照
.Refresh //刷新表数据 .compile,//提交数据. .connect to host //链接到服务器 .disconnect from all databases //断开链接 . ...
- DLib库Base64编解码示例
代码 #include <iostream> #include <fstream> #include <sstream> #include <string&g ...
- android.telephony.SmsManager.sendMultipartTextMessage
smsManager.sendMultipartTextMessage(destAddress, null, divideContents, sentIntents, null); next step ...
- ThinkPHP学习(三)
我们已经将数据保存到了后台数据库,那接下来我们肯定要将数据显示出来看看了. 先建立一个要显示数据的模板formlist.html: <!DOCTYPE HTML PUBLIC "-// ...
- ios 协议分析
1 基本用途 可以用来声明一大堆方法(不能声明成员变量) 只要某个类遵守了这个协议,就相当于拥有了这个协议中的所有方法声明 只要父类遵守了某个协议,就相当于子类也遵守了 2 格式 协议的编写 @pro ...
- xcode9报错 Safe Area Layout Guide before iOS9.0
运行工程的时候会遇到 Safe Area Layout Guide before iOS9.0 这是因为xcode9 storyboard的设置里面多了 个 Safe Area Layout Gu ...
- 【struts2】Struts2的系统架构
Struts2的官方文档里附带了Struts2的架构图,下面这张图上展示了Struts2的内部模块,以及它们的运行流程. 这张图上分了好多块,彼此之间相互联系,先浏览一下各块的名字,再留心一下运行图最 ...
- 安卓 AsyncHttpClient - “Content-Type not allowed!”
使用 http://loopj.com/android-async-http/ 的异步网络请求工具使用BinaryHttpResponseHandler来完成文件下载时总是报错,“org.apache ...
- getServletContext()接口解析(收藏)
javax.servlet.ServletContext接口 一个servlet上下文是servlet引擎提供用来服务于Web应用的接口.Servlet上下文具有名字(它属于Web应用的名字)唯一映射 ...