可以封装一个组件进行全局调用,可以参考以下案例:@Entry @Component export struct LoadingPage { @Prop flag: boolean; build() { Row() { LoadingProgress().color(Color.White).width(50).height(50) } .height(this.flag ? '100%' : 0) .width('100%') .position({ x: 0, y: 0 }) .backgroundColor('#4D000000') .justifyContent(FlexAlign.Center) } }调用:import { LoadingPage } from './LoadingPage' @Entry @Component struct PageThree { @State flag: boolean = false; // 控制是否加载 build() { Column() { Button('加载动画').onClick((event: ClickEvent) => { this.flag = !this.flag; }) LoadingPage({ flag: this.flag }); } .height('100%') .width('100%') .alignItems(HorizontalAlign.Start) .justifyContent(FlexAlign.Start) } }
可以封装一个组件进行全局调用,可以参考以下案例:
调用: