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

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

本篇咱們將繼續推動外賣項目—商品頁的展現。css3

圖片描述

如圖所示,咱們能夠把商品也面分爲兩大部分:web

  • 左側「菜單欄」;
  • 右側商品展現;

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

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

細化左側菜單欄佈局

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

<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美化左側菜單欄的內容:flexbox

.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;
}

左側菜單欄結構,美化如今就已經完成了。url

細化右側商品列表spa

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

<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(btn_yellow_highlighted@2x.png) 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;

總結

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

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

相關文章
相關標籤/搜索