跳至主要內容

商品纵向详情

起凡大约 2 分钟起凡商城小程序商品详情

商品纵向详情

效果
效果

源码解析

骨架

从上到下分别显示

  • 封面
  • 标题
  • 标签
  • 价格和品牌
<template>
  <div class="product-cover">
    <!-- 图片的高度自适应,宽度固定 -->
    <image
      class="cover"
      mode="widthFix"
    ></image>
    <div class="title">
    </div>
    <div class="tags">
    </div>
    <div class="price-brand">
    </div>
  </div>
</template>

提示

mode="widthFix"可以使得图片的宽度固定,高度自适应

封面和标题

<template>
  <div class="product-cover">
    <image
      :src="product.cover"
      class="cover"
      mode="widthFix"
      :style="{ width }"
    ></image>
    <div class="title">
      {{ product.name }}
    </div>
    <div class="tags">
    </div>
    <div class="price-brand">
    </div>
  </div>
</template>



 


 


 







标签价格品牌

<template>
  <div class="product-cover">
    <image
      :src="product.cover"
      class="cover"
      mode="widthFix"
      :style="{ width }"
    ></image>
    <div class="title">
      {{ product.name }}
    </div>
    <div class="tags">
      <!-- 循环tag列表 -->
      <nut-tag
        v-for="tag in product.tags"
        :key="tag"
        class="tag"
        color="#E9E9E9"
        textColor="#999999"
      >
        {{ tag }}
      </nut-tag>
    </div>
    <div class="price-brand">
      <div class="price">¥{{ product.price }}</div>
      <div class="brand">
        <nut-tag type="primary">{{ product.brand }}</nut-tag>
      </div>
    </div>
  </div>
</template>












 
 
 
 
 
 
 
 
 
 


 
 
 
 



源码

<template>
  <div class="product-cover">
    <image
      :src="product.cover"
      class="cover"
      mode="widthFix"
      :style="{ width }"
    ></image>
    <div class="title">
      {{ product.name }}
    </div>
    <div class="tags">
      <nut-tag
        v-for="tag in product.tags"
        :key="tag"
        class="tag"
        color="#E9E9E9"
        textColor="#999999"
      >
        {{ tag }}
      </nut-tag>
    </div>
    <div class="price-brand">
      <div class="price">¥{{ product.price }}</div>
      <div class="brand">
        <nut-tag type="primary">{{ product.brand }}</nut-tag>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ProductDto } from "@/apis/__generated/model/dto/ProductDto";
withDefaults(
  defineProps<{
    product: ProductDto["ProductRepository/COMPLEX_FETCHER"];
    width?: string;
  }>(),
  { width: "100%" },
);
</script>

<style lang="scss">
@import "../../app.scss";
.product-cover {
  border-radius: 15px;
  background-color: #ffffff;
  padding: 14px;
  position: relative;

  .cover {
    border-radius: 10rpx;
  }

  .title {
    font-size: 28rpx;
    margin-top: 5px;
    color: rgba(black, 0.9);
    @include text-max-line(2);
  }
  .tags {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    .tag {
      margin-right: 10px;
      --nut-tag-font-size: 18px;
    }
  }
  .price-brand {
    margin-top: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .price {
      color: rgba(red, 0.9);
    }
    .brand {
      --nut-tag-font-size: 18px;
      display: flex;
      align-items: center;
    }
  }
}
</style>