源码:
// 自定义组件 @Component struct PokemonInfo{ @State imageUrl: string = ''; PokemonNum: string = '' PokemonName: string = '' PokemonAttribute:string = '' build(){ Row({space:5}){ Image($r(this.imageUrl)) .height('90%') .width('40%') Column({space:2}){ Text(`编号:${this.PokemonNum}`) .width('90%') .height('30%') .fontSize(15) .textAlign(TextAlign.Start) Text(`名称:${this.PokemonName}`) .width('90%') .height('30%') .fontSize(15) .textAlign(TextAlign.Start) Text(`属性:${this.PokemonAttribute}`) .width('90%') .height('30%') .fontSize(15) .textAlign(TextAlign.Start) } }.width('90%').height('20%').border({ width: 1 }) } } @Entry @Component struct Test8{ build(){ Column({space:7}){ Text('全国图鉴') .fontSize(20) .textAlign(TextAlign.Center) .width('100%') .margin(10) PokemonInfo({PokemonNum:'001',PokemonName:'妙蛙种子',PokemonAttribute:'草 毒',imageUrl:'app.media.miaowazhongzi'}) PokemonInfo({PokemonNum:'002',PokemonName:'妙蛙草',PokemonAttribute:'草 毒',imageUrl:'app.media.miaowacao'}) PokemonInfo({PokemonNum:'003',PokemonName:'妙蛙花',PokemonAttribute:'草 毒',imageUrl:'app.media.miaowahua'}) PokemonInfo({PokemonNum:'003',PokemonName:'超级妙蛙花',PokemonAttribute:'草 毒',imageUrl:'app.media.Megamiaowahua'}) } } }
自己检查发型错误应该是在调用自定义组件时传参不成功导致的,但是具体怎么改还是不知道,有前端大神懂嘛