学习地址
零基础玩转微信小程序:黑马程序员前端微信小程序开发教程,微信小程序从基础到发布全流程_企业级商城实战(含uni-app项目多端部署)
uniapp - 黑马优购 笔记地址

在这里插入图片描述
知识点
1 数据加载后 在显示页面

<view class="layout" v-if="goods_info.goods_name">

数据加载后 ,会给goods_info赋值 ,会刷新页面

2 商品轮播图
在这里插入图片描述
3 微信 图片展示
@click=“preview(index)”
在这里插入图片描述
4 html 展示
在这里插入图片描述
5 底部 uni-goods-nav 商品导航
在这里插入图片描述
数据初始化
在这里插入图片描述
商品导航 按钮点击事件
在这里插入图片描述
界面固定底部
在这里插入图片描述

 // 上面的 布局距离底部50px  防止被商品导航挡住
 .topLayout{
   padding-bottom: 50px;
  }

源码

<template>
  <view>

    <view class="layout" v-if="goods_info.goods_name">

      <view class="topLayout">
        <view class="topBannerLayout">
          <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
            <swiper-item v-for="(item , index) in goods_info.pics" :key="index">
        
              <image :src="item.pics_big" @click="preview(index)"></image>
            </swiper-item>
          </swiper>
        
        </view>
        
        <view class="centerInfoLayout">
          <!-- 商品信息区域 -->
          <view class="goods-info-box">
            <!-- 商品价格 -->
            <view class="price">{{goods_info.goods_price}}</view>
            <!-- 信息主体区域 -->
            <view class="goods-info-body">
              <!-- 商品名称 -->
              <view class="goods-name">{{goods_info.goods_name}}</view>
              <!-- 收藏 -->
              <view class="favi">
                <uni-icons type="star" size="18" color="gray"></uni-icons>
                <text>收藏</text>
              </view>
            </view>
            <!-- 运费 -->
            <view class="yf">快递:免运费</view>
          </view>
        </view>
        
        <view class="bottomTuwenLayout">
          <rich-text :nodes="goods_info.goods_introduce"></rich-text>
        </view>
      </view>
      <view class="goods_nav">
        <uni-goods-nav  :options="options" :fill="true" :button-group="buttonGroup" @click="onClick"
          @buttonClick="buttonClick" />
      </view>
     


    </view>




  </view>
</template>

<script>
  export default {
    
    data() {
      return {
        goods_info: {},
        options: [{
          icon: 'chat',
          text: '客服'
        }, {
          icon: 'cart',
          text: '购物车',
          info: 2
        }],
        buttonGroup: [{
            text: '加入购物车',
            backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
            color: '#fff'
          },
          {
            text: '立即购买',
            backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
            color: '#fff'
          }
        ],
      };
    },
    onLoad(options) {
      const goods_id = options.goods_id
      this.getGoodsDetail(goods_id)
    },
    methods: {
      async getGoodsDetail(goods_id) {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/goods/detail', {
          goods_id
        })
        if (res.meta.status !== 200) return uni.$showMsg()
        // 为 data 中的数据赋值
        res.message.goods_introduce = res.message.goods_introduce.replace(/<img /g, '<img style="display:block;" ')
          .replace(/webp/g, 'jpg')


        this.goods_info = res.message



        console.log(this.goods_info)
      },
      preview(index){
        uni.previewImage({
            // 预览时,默认显示图片的索引
            current: index,
            // 所有图片 url 地址的数组
            urls: this.goods_info.pics.map(x => x.pics_big)
          })
      },
      onClick(e){
        console.log(e)
        if (e.content.text === '购物车') {
            // 切换到购物车页面
            uni.switchTab({
              url: '/pages/cart/cart'
            })
          }
      },
      buttonClick(e){
        console.log(e)
        if (e.content.text === '加入购物车') {
            // 切换到购物车页面
            
          }
      }
    }
  }
</script>

<style lang="scss">
  .topBannerLayout {
    width: 750rpx;
    height: 750rpx;

    swiper {
      width: 100%;
      height: 100%;

      image {
        width: 100%;
        height: 100%;
      }
    }

  }

  // 商品信息区域的样式
  .goods-info-box {
    padding: 10px;
    padding-right: 0;

    .price {
      color: #c00000;
      font-size: 18px;
      margin: 10px 0;
    }

    .goods-info-body {
      display: flex;
      justify-content: space-between;

      .goods-name {
        font-size: 13px;
        padding-right: 10px;
      }

      // 收藏区域
      .favi {
        width: 120px;
        font-size: 12px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        border-left: 1px solid #efefef;
        color: gray;
      }
    }

    // 运费
    .yf {
      margin: 10px 0;
      font-size: 12px;
      color: gray;
    }
  }
  
  .topLayout{
   padding-bottom: 50px;
  }
  
  .layout{
  }

  .goods_nav {
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
  }
</style>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐