赞
踩
当前: api9 DevEco Studio 3.1.1 Release
- @Entry
- @Component
- struct Index {
- // 定义接口返回的轮播图数据
- @State HospitalPropaganda: string[] = []
- private swiperController: SwiperController = new SwiperController()
- async aboutToAppear() {
- this.getOrgInfo()
- }
- private getOrgInfo = async () => {
- try {
- const res = await this.httpBaskData()
- this.HospitalPropaganda = res
- } catch (err) {
- console.log('err111', err)
- }
- }
- // 模拟接口返回数据
- private httpBaskData = (): Promise<string[]> => {
- return new Promise((res,rej) => {
- setTimeout(() => {
- res(['https://hwkjoss-kfx-biz-dev.oss-cn-hangzhou.aliyuncs.com/6395399560128654336.jpg', 'https://hwkjoss-kfx-biz-dev.oss-cn-hangzhou.aliyuncs.com/6395399560128654336.jpg'])
- },1000)
- })
- }
-
- build() {
- Column() {
- Text('this.HospitalPropaganda的数据是:-----')
- ForEach(this.HospitalPropaganda, (item: string) => {
- Text(item)
- })
- Text('Swiper:-----')
- // if (this.HospitalPropaganda.length > 0) {
- Swiper(this.swiperController) {
- ForEach(this.HospitalPropaganda, (item: string) => {
- Image(item) // https://hwkjoss-kfx-biz-dev.oss-cn-hangzhou.aliyuncs.com/6395399560128654336.jpg
- .width('100%').height('100%').objectFit(ImageFit.Fill)
- })
- // Image('https://hwkjoss-kfx-biz-dev.oss-cn-hangzhou.aliyuncs.com/6395399560128654336.jpg')
- }
- .width('100%')
- .height(100)
- .cachedCount(2)
- .index(1)
- .autoPlay(true)
- .interval(4000)
- .indicator(true)
- .loop(true)
- .duration(1000)
- .itemSpace(0)
- .curve(Curve.Linear)
- // }
- }
- .width('100%')
- .height('100%')
- .backgroundColor('#F7F7F7')
- }
- }
运行以上代码 预览器卡死;模拟器直接闪退;真机没有试过
已经反馈给官方:
解决办法:
在Swiper最外层加一个if判断
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。