Vue實戰-商品展示切圖(7)

上次我們通過設計評價組件這個過程,瞭解到了組件設計中的良好的習慣,比如,文件夾如何支撐組件,圖片,組件路徑的存放於設置。

本篇我們將繼續推進外賣項目—商品頁的展示。

圖片描述

如圖所示,我們可以把商品也面分爲兩大部分:

  • 左側“菜單欄”;
  • 右側商品展示;

goods爲當前商品頁面的根元素。

<templete>
    <div class="goods">
        <div class="menu-wrapper"></div>    
        <div class="foods-wrapper"></div>   
    </div>
</templete>


細化左側菜單欄

我們先來細化class爲menu-wrapper的菜單內容。

 <div class="menu-wrapper">
      <ul>
        <li class="menu-item current">
          <p class="text">
            <img
              src="http://p1.meituan.net/xianfu/a4167074795cfb33d819fd0590d1545b2048.png"
              class="icon"
            >
            專場
          </p>
        </li>
        <li class="menu-item">
          <p class="text">
            <img
              src="http://p1.meituan.net/xianfu/10ba72e043ef4eca806cafb1a90a22662048.png"
              class="icon"
            >
            熱銷
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            早餐
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            促銷產品和熱賣產品
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            主食
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            超值套餐
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            小食
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            飲品
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            甜品
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
        <li class="menu-item">
          <p class="text">
            <!---->
            開心樂園餐
          </p>
          <i class="num" style="display: none;">0</i>
        </li>
      </ul>
    </div>

主要運用了css3的flexbox佈局,使用絕對定位控制商品頁在頁面區域顯示的範圍。

.goods {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  position: absolute;
  top: 190px;
  bottom: 51px;
  overflow: hidden;
  width: 100%;
}
.goods .menu-wrapper {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 85px;
  flex: 0 0 85px;
  background: #f4f4f4;
}


使用css美化左側菜單欄的內容:

.goods .menu-wrapper .menu-item {
  padding: 16px 23px 15px 10px;
  border-bottom: 1px solid #e4e4e4;
  position: relative;
}
.goods .menu-wrapper .menu-item.current {
  background: white;
  font-weight: bold;
  margin-top: -1px;
}
.goods .menu-wrapper .menu-item:first-child.current {
  margin-top: 1px;
}
.goods .menu-wrapper .menu-item .text {
  font-size: 13px;
  color: #333333;
  line-height: 17px;
  vertical-align: middle;
  -webkit-line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;

  overflow: hidden;
}
.goods .menu-wrapper .menu-item .text .icon {
  width: 15px;
  height: 15px;
  vertical-align: middle;
}
.goods .menu-wrapper .menu-item .num {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  color: white;
  background: red;
  text-align: center;
  font-size: 7px;
  line-height: 13px;
}


左側菜單欄結構,美化現在就已經完成了。

細化右側商品列表

下面我們來細化右側列表:

<div class="foods-wrapper">
      <ul>
             <li class="container-list">
          <div>
            <img src="http://p1.meituan.net/xianfu/6588840adbcfbfe2c7a43aa69d4b36da107767.jpg">
          </div>
          <div>
            <img src="http://p1.meituan.net/xianfu/378446763167442a511dc9d4c675d877144571.jpg">
          </div>
        </li>
        <li class="food-list food-list-hook">
          <h3 class="title">熱銷</h3>
          <ul>
            <li class="food-item">
              <div
                class="icon"
                style="background-image: url(&quot;http://p0.meituan.net/xianfu/35f41c0badc69352b886cc34080f1f9a232448.png.webp&quot;);"
              ></div>
              <div class="content">
                <h3 class="name">脆香油條</h3>
                <!---->
                <div class="extra">
                  <span class="saled">月售154</span>
                  <span class="praise">贊3</span>
                </div>
                <img src class="product" style="display: none;">
                <p class="price">
                  <span class="text">¥5.5</span>
                  <span class="unit">/例</span>
                </p>
              </div>
              <div class="cartcontrol-wrapper">
                <div class="cartcontrol">
                  <div class="cart-decrease" style="display: none;">
                    <span class="inner icon-remove_circle_outline"></span>
                  </div>
                  <div class="cart-count" style="display: none;"></div>
                  <div class="cart-add icon-add_circle">
                    <i class="bg"></i>
                  </div>
                </div>
              </div>
            </li>
            </ul>
        </li>
      </ul>
    </div>

通過css美化代碼

.goods .foods-wrapper {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  /* background: blue; */
}
.goods .foods-wrapper .container-list {
  padding: 11px 11px 0 11px;
  border-bottom: 1px solid #e4e4e4;
}
.goods .foods-wrapper .container-list img {
  width: 100%;
  margin-bottom: 11px;
  border-radius: 5px;
}
.goods .foods-wrapper .food-list {
  padding: 11px;
}
.goods .foods-wrapper .food-list .title {
  height: 13px;
  font-size: 13px;
  background: url([email protected]) no-repeat left center;
  background-size: 2px 10px;
  padding-left: 7px;
  margin-bottom: 12px;
}

.goods .foods-wrapper .food-list .food-item {
  display: flex;
  margin-bottom: 25px;
  position: relative;
}
.goods .foods-wrapper .food-list .food-item .icon {
  flex: 0 0 63px;
  background-position: center;
  background-size: 120% 100%;
  background-repeat: no-repeat;
  margin-right: 11px;
  height: 75px;
}
.goods .foods-wrapper .food-list .food-item .content {
  flex: 1;
}
.goods .foods-wrapper .food-list .food-item .content .name {
  font-size: 16px;
  line-height: 21px;
  color: #333333;
  margin-bottom: 10px;
  padding-right: 27px;
}
.goods .foods-wrapper .food-list .food-item .content .desc {
  font-size: 10px;
  line-height: 19px;
  color: #bfbfbf;
  margin-bottom: 8px;


總結

注意右側結構的佈局,通常在一個分類下,比如熱銷,同等結構,樣式的展示我們通常依據請求到後臺的數據循環模板就可以了。但是,先滿足功能,需求,在優化,也是沒有什麼問題的。

下一篇文章我們開始爲左側菜單欄,右側商品展示加入數據。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章