父组件
<template>
<div id="app"> <div>详情内容</div>
<button v-on:click="startCount">开始</button> <Info :startCountsub="startCountState" /> </div>
</template> <script>
import bus from '../../bus/bus.js';
import 'common/css/reset.css';
import Hello from 'components/Hello/Hello'
import Info from 'components/info'
export default {
name: 'app',
data () {
return {
startCountState:false
}
}, methods:{
startCount:function(){ this.startCountState=true;
console.log('this.startCountState:' + this.startCountState);
console.log("开始倒计时");
// bus.$emit("countDown"); 不使用bus
}
},
components: {
Hello,Info
}
}
</script> 子组件: <template>
<div class="info">
<h1>{{ msg }}</h1> <img src="../module/detail/images/test.jpg" style="width:200px"> <h2><span>{{timeout}}</span>秒倒计时,父亲传过来的值:{{startCountState}}||{{startCountsub}}</h2>
<button v-on:click="startCount">开始</button>
</div>
</template> <script>
import bus from '../bus/bus.js';
export default {
name: 'info',
props: ["startCountsub"],
data () {
return {
msg: 'Welcome to Your Vue.js App info',
timeout:60,
// startCountState: this.$parent.startCountState, //startCountsub
startCountState: this.startCountsub //就初始化的时候更新一次,但在模板里会动态更新
}
},
computed: { },
created(){
// this.countDown();
console.log(this.$parent);
bus.$on("countDown",()=>{
//this.startCountState=true
//this.countDown();
this.startCount();
}); let intval2=setInterval(()=>{
console.log('儿子:this.startCountState:' + this.startCountState);
if(this.$parent.startCountState){
this.startCountState=true; this.countDown();
clearInterval(intval2);
} },1000); },
watch: {
startCountState:'countDown'
},
methods:{
countDown:function(){
//console.log('哈this.startCountsub:' + this.startCountsub); if(this.startCountState){
let intval=setInterval(()=>{ this.timeout--;
this.timeout==0 && clearInterval(intval);
},1000);
} },
startCount:function(){ this.startCountState=true;
} } }
</script> bus import Vue from 'vue'
var bus=new Vue(); /*
bus.$on("haha1",(text)=>{
alert(text);
});
bus.$on("haha2",(text)=>{
alert('haha2:'+text);
})
*/ export default bus;

vue使用props动态传值给子组件里的函数用,每次更新,呼叫函数的更多相关文章

  1. vue 父组件动态传值至子组件

    1.进行数据监听,数据每次变化就初始化一次子组件,进行调取达到传递动态数据的目的普通的监听: watch:{ data: function(newValue,oldValue){ doSomeThin ...

  2. vue点击父组件里面的列表动态传值到子组件

    <template> <div> 爸爸 <div style="background-color:yellow;margin-top:10px" v- ...

  3. iview 父组件动态传值给子组件

    父组件 <maintenance-super :show="{'modalSuper':modalSuper,'myData':myData}" @on-close=&quo ...

  4. vue中父组件使用props或者$attras向子组件中传值

    知识点:vue中使用props或者$attras向子组件中传值 (1) props传值 子组件必须注册好要传的数据() props:['id'] (2)$attrs传值 该数据在props中,没有注册 ...

  5. vue+elementUI项目,父组件向子组件传值,子组件向父组件传值,父子组件互相传值。

    vue+elementUI项目,父组件向子组件传值,子组件向父组件传值,父子组件互相传值. vue 父组件与子组件相互通信 一.父组件给子组件传值 props 实现父组件向子组件传值. 1父组件里: ...

  6. 【转】Vue组件一-父组件传值给子组件

    Vue组件一-父组件传值给子组件 开始 Vue组件是学习Vue框架最比较难的部分,而这部分难点我认为可以分为三个部分学习,即 组件的传值 - 父组件向子组件中传值 事件回馈 - 子组件向父组件发送消息 ...

  7. vue 组件-父组件传值给子组件

    父组件通过属性,传值给子组件,子组件通过,props数组里的名称来接受父组件传过来的值. HTML部分: <div id="app"> <tmp1 :parent ...

  8. 40.VUE学习之--组件之间的数据传参父组件向子组件里传参,props的使用实例操作

    父组件向子组件里传参,props的使用实例 <!DOCTYPE html> <html> <head> <meta charset="utf-8&q ...

  9. 九、React中的组件、父子组件、React props父组件给子组件传值、子组件给父组件传值、父组件中通过refs获取子组件属性和方法

    一.概述 React中的组件: 解决html 标签构建应用的不足. 使用组件的好处:把公共的功能单独抽离成一个文件作为一个组件,哪里里使用哪里引入. [父子组件]:组件的相互调用中,我们把调用者称为父 ...

随机推荐

  1. Struts2 拦截器配置及使用

    在我的项目中有个需求,实现记录用户操作的系统日志,基于这个功能我首先想到的是Struts 的拦截器.配置一个全部Action都会拦截的拦截,写一个公用的服务.每当用户发送请求到Action 就记录相应 ...

  2. C语言 写的 表达式求值。

    有不对的地方还望指出来,让我改正.谢谢.存一个代码 #include<stdio.h> #include<stdlib.h> #include<string.h> ...

  3. hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)

    题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  4. object_test.py

    #方法,属性,私有化加双下划线 ''' __a 从外部无法访问,但是类的内部可以访问.实际上还是能在类外访问这些私有方法,尽管不应该这么做:s._A__a 如果不需要使用这种方法但是又不行让其他对象不 ...

  5. c++再探string之eager-copy、COW和SSO方案

    在牛客网上看到一题字符串拷贝相关的题目,深入挖掘了下才发现原来C++中string的实现还是有好几种优化方法的. 原始题目是这样的: 关于代码输出正确的结果是()(Linux g++ 环境下编译运行) ...

  6. NodeJS REST API with MySQL and Express

    http://www.nodewiz.biz/nodejs-rest-api-with-mysql-and-express/ NPM Modules Express felixge/node-mysq ...

  7. c/c++时间相关

    本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时.时间的获取.时间的计算和显示格式等方面进行了阐述.本文还通过大量的实例向你展示了time.h头文件中声明的 ...

  8. jquery table表格 获取选中的某一行和某一列的值

    table class="table table-hover" id="test123"> <tr> <th width="4 ...

  9. 使用Spring Security控制会话

    1.概述 在本文中,我们将说明Spring Security如何允许我们控制HTTP会话.此控件的范围从会话超时到启用并发会话和其他高级安全配置. 2.会话何时创建? 我们可以准确控制会话何时创建以及 ...

  10. 洛谷 - P4450 - 双亲数 - 整除分块

    https://www.luogu.org/fe/problem/P4450 应该不分块也可以. 求\(F(n,m,d)=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^ ...