Vue父组件向子组件传递方法(自定义方法)并且子组件向父组件传递数据
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title> <script src="./lib/vue-2.4.0.js"></script>
</head>
<body> <div class="app">
<!-- 父组件向子组件传递方法,使用的是事件绑定机制,v-on 当我们自定义一个事件属性之后,那么子组件就能够通过某些方法来
调用,传递进去的这个方法了 -->
<log v-bind:dataflog="msg" @funcshow="show" ></log>
</div> <template id="log">
<div>
<h1>这是子组件界面----{{dataflog}}</h1>
<input type="button" @click="myclick" value="父组件传递过来的方法 子组件接收">
</div>
</template> <script> var vm=new Vue({
el:'.app',
data:{
msg:'看到数据了嘛'
},
methods: {
// 父方法接受参数
show(a){
console.log(a.name+'父组件方法');
}, },
components:{
log:{
template:'#log',
props:['dataflog'],
data(){
return {
duwei:{name:'duwei',age:30}
}
},
methods: {
myclick(){
// console.log('ok');
// 当点击子组件按钮的时候,如何拿到父组件传递过来的func 方法,并调用呢?
// emit英文愿意:是触发调用 发射的意思。
// this.$emit('funcshow')
// emit传递父组件中的方法,并且子组件向父组件传递消息
// this.$emit('funcshow',123,345)
this.$emit('funcshow',this.duwei); }, },
}, }
})
</script>
</body>
</html>
Vue父组件向子组件传递方法(自定义方法)并且子组件向父组件传递数据的更多相关文章
- layer父界面调用子弹窗的方法和获取子弹窗的元素值总结
layer.open({ type: 2 ,title: false //不显示标题栏 ,closeBtn: false ,area: ['460px', '45%'] ,shade: 0.5 ,id ...
- [ExtJS5学习笔记]第七节 Extjs5的组件components及其模板事件方法学习
本文地址:http://blog.csdn.net/sushengmiyan/article/details/38487519 本文作者:sushengmiyan ------------------ ...
- layer父页面调用子页面的方法
由于不知道如何在子页面获取到layer定义的确定按钮,于是就在子页面上定义了一个方法,然后在由父页面在点确定按钮时调用子页面所定义的这个方法,从而执行子页面方法里面的内容: 子页面代码: functi ...
- window.showModalDialog刷新父窗口和本窗口的方法及注意
window.showModalDialog刷新父窗口和本窗口的方法及注意: 一.刷新父窗口的方法: A.使用window.returnValue给父窗口传值,然后根据值判断是否刷新. 在w ...
- Vue 父组件往子组件传递方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue-父组件向子组件传递方法
1.父组件向子组件传递方法,使用的是事件绑定机制 v-on:传递给子组件的方法名=“父组件中的方法”
- vue.js 同级组件之间的值传递方法(uni-app通用)
vue.js 兄弟组件之间的值传递方法 https://blog.csdn.net/jingtian678/article/details/81634149
- vue必须掌握之组件通信(7种方法)
方法一:$emit / props 父组件通过props的方式向子组件传递,子组件通过$emit触发父组件中v-on绑定的自定义事件 <!--父组件--> <template> ...
- Vue中组件通信的几种方法(Vue3的7种和Vue2的12种组件通信)
Vue3组件通信方式: props $emit expose / ref $attrs v-model provide / inject Vuex 使用方法: props 用 props 传数据给子组 ...
随机推荐
- g++编译时遇到问题undefined reference to
文件目录结构体为: src 和include 分别用来存放.cpp文件和 .hpp文件 其中:src文件夹下有需要的文件 simulator_client.cpp crc32.cpp : includ ...
- ROS学习笔记(三)
机器人建模与仿真URDF(Unified Robot Descrption Format,统一机器人描述格式),ROS提供了URDF的c++解析器.安装语法检查工具sudo apt-get insta ...
- npm publish 一直报错 404
在封装 zswui react ui 组件库的时候,尝试了下 github的 packages 包设置,然后就给自己挖坑了. zswui 这是一个从零开始配置,实现组件开发测试的项目. 因为设置 ...
- 安装私有docker仓库
简介: 虽然国内已经有了很多docker加速镜像,以前用的daocloud,最近又找到了阿里云. 但是私有网络部署kubernetes,用不了加速镜像,还是自己部署一个比较好. 一:安装docker ...
- top显示命令详解+top命令使用
http://blog.csdn.net/u014226549/article/details/22041289
- 常见的SQL注入检测语句(转载)
0x00 前言 现在很多WAF都能拦截sqlmap.havij 等注入工具的发包注入,所以这时我们需要在浏览器上使用hackerbar 进行手工注入,或者说是手工绕过注入攻击 0x01 发现SQL 注 ...
- 说说Spring XML的头
部分内容截取自(http://blog.csdn.net/zhch152/article/details/8191377,http://iswift.iteye.com/blog/1657537) 在 ...
- 客户端连接Codis集群
新建maven webapp项目 添加相关依赖: <dependency> <groupId>redis.clients</groupId> <artifac ...
- Eclipse 常用配置和基本调试
常用配置 1.显示行号:window->Preferences->General->Editors->Text Editors , 勾选show line numbers 2. ...
- git将代码提交到多个远程仓库
在项目目录下执行: git remote set-url --add origin http://mayun.cn/xxx/adsdsdsdcelery-demo.git 即可添加一个远程仓库. 再执 ...