自定义组件嵌套问题
发布于 5 年前 作者 tiantao 4013 次浏览 来自 问答

在子组件中的定义如下:

/*

 组件嵌套(组件间关系)

 */

relations:{

“…/navigation-bar/navigation-bar”:{

type:‘parent’,

linked: function (target) { //插入到/navigation-bar中时被执行

},

linkChanged:function(target){

},

unlinked:function(target){

}

}

},

在父组件中的定义如下:

/**

* 关联向下箭头组件

*/

relations:{

‘…/arrow-button-down/arrow-button-down:{

type:‘child’,

linked: function (target){

debugger

},

linkChanged: function (target){

debugger

},

unlinked: function (target){

debugger

}

}

},

其中linked;linkChanged,unlinked都没有被调用,请问这是为什么呢?这些方法都是系统自动调用的吗,还是要另外手动处理?

1 回复

同遇到,目录结构如下的两个组件,声明 relations 没有效果。

– components

    |-- component_a

        |-- component_a.js

    |-- component_b

        | – component_b.js

其中 component_a.js 中 relations 定义如下:

relations: {
  '../component_b/component_b': {

    type: 'child',

   linked: function(target) { console.log(target); }

  }
}

component_b.js 中 relations 为:

relations: {
  '../component_a/component_a': {

    type: 'parent',

   linked: function(target) { console.log(target); }

  }
}
回到顶部