<custom-form>
<custom-input>custom-input>
custom-form>
component({
options: {
// 启用组件间关系定义段
relations: true,
},
})
// custom-form.js
component({
relations: {
'./custom-input': {
type: 'child',
linked(target) {
// 每次有 input 插入时(attached 生命周期之后)执行,target 是 input 节点实例
},
linkchanged(target) {
// 每次有 input 移动后(moved 生命周期之后)执行,target 是 input 节点实例
},
unlinked(target) {
// 每次有 input 移除时(detached 生命周期之后)执行,target 是 input 节点实例
},
},
},
ready() {
// 同时提供 getrelationnodes 可查询当前定义的有序关系数组
console.log(this.getrelationnodes('./custom-input'));
},
})
// custom-input.js
component({
relations: {
'./custom-form': {
type: 'parent',
linked(target) {
// 每到插入到 form 时(attached 生命周期之后)执行,target 是 from 节点实例
},
linkchanged(target) {
// 每次移动后(moved 生命周期之后)执行,target 是 from 节点实例
},
unlinked(target) {
// 每次移除时(detached 生命周期之后)执行,target 是 from 节点实例
},
},