美文网首页hybrid APP(ionic)Ios@IONICIonic3项目实战教程
ionic3项目实战教程 - 第8讲 ionic3商品详情页的实

ionic3项目实战教程 - 第8讲 ionic3商品详情页的实

作者: IonicBlog | 来源:发表于2017-08-23 22:09 被阅读1971次

这一讲主要包含以下几个部分:

  • 1.创建商品详情页
  • 2.获取商品详情页的数据
  • 3.展示商品详情页的数据

1.创建商品详情页

执行 ionic g page product-details

8-1.png

实现点击商品列表项时跳转到商品详情页:

在ion-products.html中增加(click)="goDetails(p)"事件,实现跳转:
ion-products.ts增加goDetails()函数,

  goDetails(item) {
    this.navCtrl.push('ProductDetailsPage', { item: item });
  }

2.获取商品详情页的数据

这里只需要展示商品标题、价格、介绍、和图片;

product-details.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-product-details',
  templateUrl: 'product-details.html',
})
export class ProductDetailsPage {
  selectedItem: any;
  imgs: any;
  constructor(public navCtrl: NavController, public navParams: NavParams) {
      this.selectedItem = this.navParams.get("item");
      if (this.selectedItem.SmallImages) {
          this.imgs = this.selectedItem.SmallImages;
      }
  }
}

3.展示商品详情

product-details.html

<ion-header>
  <ion-navbar style="opacity: 0.8" no-border-bottom color="primary">
    <ion-title>商品详情</ion-title>
  </ion-navbar>
</ion-header>
<ion-content fullscreen>
  <ion-row>
    <ion-col>
     < img src="{{selectedItem.PictUrl}}" alt="">
    </ion-col>
  </ion-row>
  <div class="item-good">
    <div class="list-price buy">
      <span class="price-new ml"><i>¥</i>{{selectedItem.ZkFinalPrice}}</span>
      <i class="del f14 ml2">¥{{selectedItem.ReservePrice}}</i>
    </div>
    <h1>{{selectedItem.Title}}</h1>
  </div>
  <button ion-button full primary Ï>去抢购</button>
  <div *ngFor="let img of imgs">
    < img src="{{img}}" alt="">
  </div>
</ion-content>

product-details.scss

page-product-details {
  ion-col {
    padding: 0px;
  }
  .item-good .list-price {
    width: 96%;
    height: 34px;
    line-height: 35px;
    bottom: 0;
    padding: 2% 0;
  }
  .list-price .ml {
    color: #f8285c;
    margin-left: 27%;
  }
  .item-good h1 {
    width: 96%;
    font-size: 16px;
    font-weight: 500;
    color: rgba(102, 102, 102, 1);
    padding: 2%;
    text-align: center;
  }
  .item-good .list-price .f14 {
    font-size: 14px;
  }
  .item-good .list-price i {
    font-style: normal;
    font-size: 30px;
  }
  .item-good .price-new {
    font-size: 30px;
  }
  .list-price .ml2 {
    margin-left: 2%;
  }
  .item-good .del {
    color: rgba(171, 171, 171, 1);
    text-decoration: line-through;
  }
}

到这里商品详情页就完成了,试试看首页的商品列表,和分类的商品列表,点击都可以跳转到详情的界面,是不是再一次感受到封装带来的便捷。

看下效果

8-2.gif

下一讲讲将介绍如何使用应用内主题浏览器,官方资料:http://ionicframework.com/docs/native/themeable-browser/

完!

相关文章

网友评论

  • 等等_70cd:能实现滑动切换商品么swiper实现 跟上下滚动有点冲突
  • 1aa3e6899064:我的点击详情报错 ERROR Error: Uncaught (in promise): invalid link: ProductDetailsPage这个是怎么回事
    8742b64264a7:ionic g page 后记得重新ionic serve
    简单就好_fbba:新建的时候不要在app.module.ts中加ProductDetailsPage这个,就不会了
  • c2a75f1e3c0d:你的接口是在哪里调的呢 可以加下qq765477727 详细咨询下吗
  • Spon9e:请问楼主的图片等数据来源通过在线的方式,比如这张图的url:http://img1.tbcdn.cn/tfscom/i1/TB1MXraLXXXXXaBXFXXXXXXXXXX_!!0-item_pic.jpg
    我是小白,想问下是通过什么技术实现的呢,请问是自己搭的服务器吗?:flushed:
    c2a75f1e3c0d:你的接口是在哪里调的呢 可以加下qq765477727 详细咨询下吗
    Spon9e:@IonicBlog 好的谢谢!我在看看😬
    IonicBlog:@Spon9e 这是淘宝的素材
  • 89a1892f44f2:最下面的tab页是怎么隐藏的呢?
  • 2d6182223e59:![]({{selectedItem.PictUrl}})中的![]是什么意思?
    IonicBlog:@大内低手的 是一个img标签,因为教程是markdown写的,所以被自动转换了
    c74bbe5501f1:@咷椛嶋紸 同问
  • 据呵呵: @TongeBlog 大神,图片查看组建有没有做过,图片可以缩放,
    IonicBlog:搜索swiper

本文标题:ionic3项目实战教程 - 第8讲 ionic3商品详情页的实

本文链接:https://www.haomeiwen.com/subject/fcntdxtx.html