Vue中$parent 和$children的使用
来源:互联网 发布:阿里云 smtp发不出 编辑:程序博客网 时间:2024/05/20 05:57
$parent 该组件实例的父级组件实例
$children 该组件实例的子组件实例
上代码
html部分
<div id='box'> <parent ref='pa'></parent></div>
script部分
Vue.component('parent',{ template:`<div><h1>父组件</h1><child></child></div>`, components:{ 'child':{ template:`<div><h2>这是子组件</h2></div>` } }})new Vue({ el:'#box', created:function(){ this.$nextTick(()=> console.log(this.$refs.pa.$parent) //打印的name为<Root>即根实例 ) }})
再次测试一下
new Vue({ el:'#box', created:function(){ this.$nextTick(()=> console.log(this.$refs.pa.$parent==this) //显示为true ) }})
测试一下$children
new Vue({ el:'#box', created:function(){ this.$nextTick(()=> console.log(this.$refs.pa.$children) //显示为一个数组 ) }})
为什么不直接是一个组件实例呢?
再次看了看Vue的API。原来$children的数据类型就是Array!
阅读全文
0 0
- Vue中$parent 和$children的使用
- vue组件($children,$refs,$parent)的使用
- vue组件($children,$refs,$parent)的使用
- jquery 中查找函数parent ,parents,find和children的一点研究
- jquery获取parent,children的使用父亲子类用法
- ORACLE parent latch和children latch
- Jquery的parent,parents与children
- Jquery中next和children的区别
- Jquery中next和children的区别
- javascript中children和childNodes的区别
- javascript中children和childNodes的区别
- Flex中Elements和Children的区别
- jQuery中children()和find()的区别
- JS中,children和childNodes的不同之处
- jquery中find()和children()的区别
- children与parent
- spring bean中parent的使用
- jquery使用find,parent,children,next,prev等方法判断取得值是否为空的方法
- React-Router使用
- JAVA数据结构之循环队列的实现
- 磁盘加锁结论
- Java多线程系列--“基础篇”11之 生产消费者问题
- 7.7
- Vue中$parent 和$children的使用
- Android 修改基础库的包名 流程
- Android事件分发机制
- log4j2下载及用法简介
- 【hadoop Sqoop】Sqoop从mysql导数据到hdfs
- ThinkPHP 3.1.2 增删查改特性
- js继承之组合继承
- 极限编程/敏捷开发
- HDU2838-简单树状数组