@Builder函数传值问题咨询,以下场景,无法渲染出全部组件。有注意事项吗
咨询场景描述:
interface Pos {
x: number;
y: number;
}
@Builder function overBuilder($$: Pos) {
Row() {
Column() {
Text(改变位置).position({x:$$.x, y:$$.y})
HelloComponent({positionXNum: $$.x, positionYNum: $$.y})
}
}
}
@Component
struct HelloComponent {
@Link positionXNum: number;
@Link positionYNum: number;
build() {
Row() {
Text(当前X= + this.positionXNum)
Text(当前Y= + this.positionYNum)
}
}
}
@Entry
@Component
struct Parent {
// @State pos: Pos = new Pos();
@State pos: Pos = { x: 0, y: 0 };
@State posX: number = 0;
@State posY: number = 0;
build() {
Column() {
// Pass the this.label reference to the overBuilder component when the overBuilder component is called in the Parent component.
// overBuilder({pos: this.pos})
overBuilder(this.pos)
Button(‘Click me’).onClick(() => {
// After Click me is clicked, the UI text changes from Hello to ArkUI.
this.posX = this.posX+100;
this.posY = this.posY+100;
})
}
}
}
可以参考如下demo: