在项目中引用HAR,本文介绍采用从本地文件夹安装以及从本地压缩包安装两种方式。


@Component
export struct MainPage {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize($r('app.float.page_text_font_size'))
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.message = 'Welcome';
});
}
.width('100%');
}
.height('100%');
}
} import { MainPage } from 'localfolderpack';
@Entry
@Component
struct WidgetCard {
build() {
Row() {
MainPage();
}
.width('100%')
.height('100%')
.backgroundColor($r('sys.color.comp_background_primary'));
}
} 

@Component
export struct MainPage {
isShow: boolean = true;
build() {
Column() {
if (this.isShow) {
Row() {
Text('localZipPack hello')
.fontSize(20);
};
} else {
Row() {
Text('localZipPack hi')
.fontSize(20);
};
}
}
.padding(16)
.width('100%')
.height('100%');
}
} import { MainPage } from 'localzippack';
@Entry
@Component
struct WidgetCard {
build() {
Row() {
MainPage({ isShow: false });
};
}
@Builder
MainPageImport() {
Column();
Text();
Row();
if (true) {
}
}
}