vue寻任意组件实例(iview源码)

vue 寻任意组件实例(iview 源码)二七惨案
findComponentUpward
由⼀个组件,向上到最近的指定组件;
findComponentsUpward
国企备忘录>强捻纱由⼀个组件,向上到所有的指定组件;
findComponentDownward
由⼀个组件,向下到最近的指定组件;
findComponentsDownward
由⼀个组件,向下到所有指定的组件;
findBrothersComponents
由⼀个组件,到指定组件的兄弟组件// Find components upward function  findComponentUpward  (co
ntext , componentName , componentNames ) {    if  (typeof  componentName === 'string') {        componentNames = [componentName ];    } else  {        componentNames = componentName ;    }    let  parent = context .$parent ;    let  name = parent .$options .name ;    while  (parent && (!name || componentNames .indexOf (name ) < 0)) {        parent = parent .$parent ;        if  (parent ) name = parent .$options .name ;    }    return  parent ;}export  {findComponentUpward };// Find component downward export  function  findComponentDownward  (context , componentName ) {    const  childrens = context .$children ;    let  children = null ;    if  (childrens .length ) {        for  (const  child of  childrens ) {            const  name = child .$options .name ;            if  (name === componentName ) {                children = child ;                break ;            } else  {                children = findComponentDownward (child , componentName );                if  (children ) break ;            }        }    }    return  children ;}// Find components downward export  function  findComponentsDownward  (context , componentName , ignoreComponentNames = []) {    if  (!Array .isArray (ignoreComponentNames )) {        ignoreComponentNames = [ignoreComponentNames ];    }    return  context .$children .reduce ((components , child ) => {        if  (child .$options .name === componentName ) components .push (child );        if  (ignoreComponentNames .indexOf (child .$options .name ) < 0) {            const  foundChilds = findComponentsDownward (child , componentName );            return  components .concat (foundChilds );        } else  {            return  components ;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
nc440033
34
35
36
37
38
39
40
41
42
43
44
45
46
已来的主人翁47
48
49
50
后结构主义
return  components ;        }    }, []);}// Find components upward export  function  findComponentsUpward  (context , componentName ) {    let  parents = [];    const  parent = context .$parent ;    if  (parent ) {        if  (parent .$options .name === componentName ) parents .push (parent );        return  parents .concat (findComponentsUpward (parent , componentName ));    } else  {        return  [];    }}// Find brothers components export  function  findBrothersComponents  (context , componentName , exceptMe = true ) {    let  res = context .$parent .$children .filter (item => {        return  item .$options .name === componentName ;    });    let  index = res .findIndex (item => item ._uid === context ._uid );    if  (exceptMe ) res .splice (index , 1);    return  res ;}5051525354
555657585960616263646566676869707172737475

本文发布于:2024-09-21 12:44:47,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/396795.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:组件   找到   指定   实例
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议