W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
步驟導(dǎo)航器組件,適用于引導(dǎo)用戶按照步驟完成任務(wù)的導(dǎo)航場景。
該組件從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。
Stepper(value?: { index?: number })
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
index | number | 否 | 設(shè)置步驟導(dǎo)航器當(dāng)前顯示StepperItem的索引值。 默認(rèn)值:0 |
名稱 | 描述 |
---|---|
onFinish(callback: () => void) | 步驟導(dǎo)航器最后一個StepperItem的nextLabel被點擊時,并且ItemState屬性為Normal時,觸發(fā)該回調(diào) 。 |
onSkip(callback: () => void) | 當(dāng)前顯示的StepperItem狀態(tài)為ItemState.Skip時,nextLabel被點擊時觸發(fā)該回調(diào)。 |
onChange(callback: (prevIndex?: number, index?: number) => void) | 點擊當(dāng)前StepperItem的prevLabel進(jìn)行步驟切換時觸發(fā)該回調(diào);或點擊當(dāng)前StepperItem的nextLabel,當(dāng)前頁面不為步驟導(dǎo)航器最后一個StepperItem且ItemState屬性為Normal時,觸發(fā)該回調(diào)。 - prevIndex:切換前的步驟頁索引值。 - index:切換后的步驟頁(前一頁或者下一頁)索引值。 |
onNext(callback: (index?: number, pendingIndex?: number) => void) | 點擊StepperItem的nextLabel切換下一步驟時,當(dāng)前頁面不為步驟導(dǎo)航器最后一個StepperItem且ItemState屬性為Normal時,觸發(fā)該回調(diào)。 - index:當(dāng)前步驟頁索引值。 - pendingIndex:下一步驟頁索引值。 |
onPrevious(callback: (index?: number, pendingIndex?: number) => void) | 點擊StepperItem的prevLabel切換上一步驟時觸發(fā)該回調(diào)。 - index:當(dāng)前步驟頁索引值。 - pendingIndex:上一步驟頁索引值。 |
- // xxx.ets
- @Styles function itemStyle () {
- .width(336)
- .height(621)
- .margin({ top: 48, left: 12 })
- .borderRadius(24)
- .backgroundColor('#FFFFFF')
- }
- @Extend(Text) function itemTextStyle () {
- .fontColor('#182431')
- .fontSize(36)
- .fontWeight(500)
- .opacity(0.4)
- .margin({ top: 82, bottom: 40 })
- }
- @Entry
- @Component
- struct StepperExample {
- @State currentIndex: number = 0
- @State firstState: ItemState = ItemState.Normal
- @State secondState: ItemState = ItemState.Normal
- @State thirdState: ItemState = ItemState.Normal
- build() {
- Stepper({
- index: this.currentIndex
- }) {
- // 第一個步驟頁
- StepperItem() {
- Column() {
- Text('Page One')
- .itemTextStyle()
- Button('change status:' + this.firstState)
- .backgroundColor('#007dFF')
- .onClick(() => {
- this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
- })
- }.itemStyle()
- }
- .nextLabel('Next')
- .status(this.firstState)
- // 第二個步驟頁
- StepperItem() {
- Column() {
- Text('Page Two')
- .itemTextStyle()
- Button('change status:' + this.secondState)
- .backgroundColor('#007dFF')
- .onClick(() => {
- this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled
- })
- }.itemStyle()
- }
- .nextLabel('Next')
- .prevLabel('Previous')
- .status(this.secondState)
- // 第三個步驟頁
- StepperItem() {
- Column() {
- Text('Page Three')
- .itemTextStyle()
- Button('change status:' + this.thirdState)
- .backgroundColor('#007dFF')
- .onClick(() => {
- this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
- })
- }.itemStyle()
- }
- .status(this.thirdState)
- // 第四個步驟頁
- StepperItem() {
- Column() {
- Text('Page Four')
- .itemTextStyle()
- }.itemStyle()
- }
- }
- .backgroundColor('#F1F3F5')
- .onFinish(() => {
- // 此處可處理點擊最后一頁的Finish時的邏輯,例如路由跳轉(zhuǎn)等
- console.info('onFinish')
- })
- .onSkip(() => {
- // 此處可處理點擊跳過時的邏輯,例如動態(tài)修改Stepper的index值使其跳轉(zhuǎn)到某一步驟頁等
- console.info('onSkip')
- })
- .onChange((prevIndex: number, index: number) => {
- this.currentIndex = index
- })
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: