赞
踩
- interface Item {
- name: String,
- price: Number
- }
-
- @Entry
- @Component
- struct Index {
- private arr:Array<Item> = [
- {name: '华为 Meta 50', price: 6999},
- {name: '华为 Meta 60 pro', price: 7999},
- {name: '华为 Meta X5', price: 12999},
- ];
-
- build() {
- Column({space: 30}) {
- ForEach(
- this.arr,
- item=>{
- Row(){
- Column() {
- Text(item.name)
- .fontWeight(FontWeight.Bold)
- .margin({bottom: 10})
- Text('¥' + item.price)
- }
- }
- .width('100%')
- .backgroundColor("#FFF")
- .padding(20)
- }
- )
- }
- .height('100%')
- .backgroundColor("#999")
- .justifyContent(FlexAlign.Center)
- };
- }

- interface Item {
- name: String,
- price: Number,
- discount?: Number
- }
-
- @Entry
- @Component
- struct Index {
- private arr:Array<Item> = [
- {name: '华为 Meta 50', price: 6999, discount: 6666},
- {name: '华为 Meta 60 pro', price: 7999},
- {name: '华为 Meta X5', price: 12999},
- ];
-
- build() {
- Column({space: 30}) {
- ForEach(
- this.arr,
- item=>{
- Row(){
- Column() {
- if(item.discount){
- Text(item.name)
- .fontWeight(FontWeight.Bold)
- .margin({bottom: 10})
- Text('原价:¥' + item.price)
- .fontSize(14)
- .decoration({ type: TextDecorationType.LineThrough })
- Text('折扣价:¥' + item.discount)
- .textAlign(TextAlign.Start)
- Text('补贴:¥' + (item.price - item.discount))
- .textAlign(TextAlign.Start)
- }else{
- Text(item.name)
- .fontWeight(FontWeight.Bold)
- .margin({bottom: 10})
- Text('¥' + item.price)
- }
- }
- }
- .width('100%')
- .backgroundColor("#FFF")
- .padding(20)
- }
- )
- }
- .height('100%')
- .backgroundColor("#999")
- .justifyContent(FlexAlign.Center)
- };
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。