子组件:

<template>
<div class="child">
<slot name='meiyong'></slot>
<p >我是子组件哟 {{num}} {{ttttt}} {{nike}} 这是我独有的----->{{isChi}} </p>
<slot name="strong"></slot>
</div>
</template>
<script>
import Utils from '@/utils/utils'
export default {
props:['ttttt','nike'],
data(){
return {
num:" ",
isChi:'★子组件独有★'
}
},
mounted(){
//传值给父组件
this.$parent.runTime= Utils.formatDate(new Date(), "YYYY-MM-DD hh:mm:ss");
} }
</script>
<style lang="scss" scoped>
.child{
height: 5rem;
width: %;
background-color: skyblue;
text-align: center;
position: relative;
p{
height: 30px;
width: 800px;
display: block;
position: absolute;
top: ;
bottom: ;
left: ;
right: ;
margin: auto;
// transform: translate(-50%,-50%)
}
.parent{
color:greenyellow;
}
.strong{
position: absolute;
bottom: ;
left: %;
transform: translateX(-%);
color: darkmagenta;
}
}
</style>

父组件:

<template>
<div >
<!-- 父传子-->
<tc :ttttt='mongodb' :nike='nike' ref="toChild">
<template v-slot:meiyong >
<h1 class="parent">v-slot中的内容 没用?呵呵</h1>
</template>
<template v-slot:strong>
<h2 class="strong">你很强???{{runTime}} </h2>
</template>
</tc>
</div>
</template>
<script>
import testChild from '@/views/testChild'
export default {
data(){
return {
ttttt:'█我是父组件给child传的值█',
mongodb:'█我是MongoDB哟█',
nike:'███ just do ███',
runTime:'null'
}
},
mounted(){
let chi = this.$refs.toChild
console.log('chi===>',chi.isChi);
this.$refs.toChild.isChi = '我试试能不能修改子组件的值' // num不是传的值 所以要ref才能传
this.$refs.ttttt.num = ''
},
components:{
tc:testChild
}
}
</script>
<style lang="scss" scoped> </style>

Vue父子组件传值$parent , ref,$refs,props大总结的更多相关文章

  1. 一个故事讲懂vue父子组件传值

    作者:李佳明同学链接:https://www.jianshu.com/p/2272b6ca0f0c 一个故事讲懂vue父子组件传值 讲故事前先讲代码 父组件向子组件传值 父组件数据传递给子组件可以通过 ...

  2. VUE父子组件传值问题

    一.父组件向子组件传递数据 组件实例的作用域是孤立的.这意味着不能(也不应该)在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,我们需要通过子组件的props选项. 1.静态props ...

  3. vue父子组件传值

    1.父组件向子组件传值 例如app.vue是父组件,v-header.vue是子组件,实现app向v-header传值父组件需要自定义自己的title值, 子组件v-header内容 <temp ...

  4. vue父子组件的传值总结

    久违的博客园我又回来了.此篇文章写得是vue父子组件的传值,虽然网上已经有很多了.写此文章的目的就是记录下个人学习的一部分.接下来我们就进入主题吧! 在开发vue项目中,父子组件的传值是避免不掉的. ...

  5. vue组件定义方式,vue父子组件间的传值

    vue组件定义方式,vue父子组件间的传值 <!DOCTYPE html> <html lang="zh-cn"> <head> <met ...

  6. vue父子组件之间传值

    vue父子组件进行传值 vue中的父子组件,什么是父组件什么是子组件呢?就跟html标签一样,谁包裹着谁谁就是父组件,被包裹的元素就是子组件. 父组件向子组件传值 下面用的script引入的方式,那种 ...

  7. 【转】vue父子组件之间的通信

    vue父子组件之间的通信 在vue组件通信中其中最常见通信方式就是父子组件之中的通性,而父子组件的设定方式在不同情况下又各有不同.最常见的就是父组件为控制组件子组件为视图组件.父组件传递数据给子组件使 ...

  8. vue父子组件通信高级用法

    vue项目的一大亮点就是组件化.使用组件可以极大地提高项目中代码的复用率,减少代码量.但是使用组件最大的难点就是父子组件之间的通信. 子通信父 父组件 <template> <div ...

  9. vue父子组件传值加例子

    例子:http://element-cn.eleme.io/#/zh-CN/component/form         上进行改的 父传子:用prop:子组件能够改变父组件的值,是共享的,和父操作是 ...

随机推荐

  1. 编译安装PTLib和H.323 Plus Core

    下载PTLib和H.323 Plus Core,官方网站很容易下载:http://www.h323plus.org/source/. 我下载这两个库后存放到目录/home/ynq/h323plus下, ...

  2. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary

    链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is a ...

  3. java常用函数

    if(null == list || list.size() ==0 ){ } list.isEmpty()和list.size()==0 没有区别 isEmpty()判断有没有元素而size()返回 ...

  4. sz/rz

    需要客户端的支持,CRT或者Xshell等 linux端默认是不支持的, 不用通过传输工具来传输文件 yum -y install lrzsz

  5. [Luogu] 1600

    https://www.luogu.org/problemnew/show/P1600 nlogn竟然T了 #include <iostream> #include <cstdio& ...

  6. VMWare Fusion 8 序列号

    FY75A-06W1M-H85PZ-0XP7T-MZ8E8 ZY7TK-A3D4N-08EUZ-TQN5E-XG2TF FG1MA-25Y1J-H857P-6MZZE-YZAZ6

  7. windows平台下MySQl的安装、破解和使用

    #1.下载:MySQL Community Server 5.7.16 http://dev.mysql.com/downloads/mysql/ #2.解压 如果想要让MySQL安装在指定目录,那么 ...

  8. windows游戏编程X86 32位保护模式下的内存管理概述(一)

    本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/22445945 作者:jadeshu   邮箱: jades ...

  9. 区间DP小结 及例题分析:P1880 [NOI1995]石子合并,P1063 能量项链

    区间类动态规划 一.基本概念 区间类动态规划是线性动态规划的拓展,它在分阶段划分问题时,与阶段中元素出现的顺序和由前一阶段的那些元素合并而来由很大的关系.例如状态f [ i ][ j ],它表示以已合 ...

  10. Memcached 之在win10上的安装

    一.下载 http://static.runoob.com/download/memcached-win64-1.4.4-14.zip 二.安装 memcached <1.4.5 版本安装 1. ...