1.更新readme.md
2.更新hvigor-ohos-plugin版本由2.0.0到2.4.2 Signed-off-by: 李艺为 <liyiwei18@h-partners.com>
This commit is contained in:
parent
8494070fb0
commit
9bf705c711
|
@ -2,3 +2,9 @@
|
|||
/local.properties
|
||||
/.idea
|
||||
**/build
|
||||
/oh_modules/
|
||||
/.hvigor/
|
||||
/oh-package-lock.json5
|
||||
/.clangd
|
||||
/.clang-format
|
||||
/.clang-tidy
|
||||
|
|
63
README.md
63
README.md
|
@ -22,17 +22,38 @@ ohpm install @ohos/imageknife
|
|||
```
|
||||
|
||||
## 使用说明
|
||||
### 0.依赖配置
|
||||
|
||||
1.在AbilityStage.ts中,初始化全局ImageKnife实例。
|
||||
0.1.在项目中entry/oh-package.json5中做如下修改,然后点击Sync Now:
|
||||
```json5
|
||||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"@ohos/imageknife": "^2.0.2"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
0.2.在entry\src\main\ets\entryability\EntryAbility.ts中做如下配置初始化全局ImageKnife实例:
|
||||
|
||||
```typescript
|
||||
import AbilityStage from "@ohos.application.AbilityStage"
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import window from '@ohos.window';
|
||||
import { ImageKnife } from '@ohos/imageknife'
|
||||
|
||||
export default class MyAbilityStage extends AbilityStage {
|
||||
onCreate() {
|
||||
// 初始化全局ImageKnife实例,在AbilityStage.ts中调用ImageKnife.with(this.context)进行初始化
|
||||
globalThis.ImageKnife = ImageKnife.with(this.context)
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
globalThis.ImageKnife = ImageKnife.with(this.context);
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -42,28 +63,28 @@ export default class MyAbilityStage extends AbilityStage {
|
|||
接下来我们来写个简单实例看看:
|
||||
|
||||
```typescript
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{ // 加载一张本地的jpg资源(必选)
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
// 占位图使用本地资源icon_loading(可选)
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
// 失败占位图使用本地资源icon_failed(可选)
|
||||
errorholderSrc: $r('app.media.icon_failed')
|
||||
};
|
||||
@State message: string = 'Hello World'
|
||||
@State option: ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.icon')
|
||||
}
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 })
|
||||
.width(300) // 自定义组件支持通用属性链式调用,可以直接设置宽高
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({ imageKnifeOption: this.option })
|
||||
.width(300)
|
||||
.height(300)
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
"name": "default",
|
||||
"signingConfig": "default"
|
||||
}
|
||||
]
|
||||
],
|
||||
"signingConfigs": []
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/node_modules
|
||||
/.preview
|
||||
/build
|
||||
/oh_modules/
|
||||
/oh-package-lock.json5
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"hvigorVersion": "2.0.0",
|
||||
"hvigorVersion": "2.4.2",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "2.0.0"
|
||||
"@ohos/hvigor-ohos-plugin": "2.4.2"
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
/node_modules
|
||||
/.preview
|
||||
/build
|
||||
/oh_modules/
|
||||
/oh-package-lock.json5
|
||||
|
|
Loading…
Reference in New Issue