Vue.js高仿餓了么外賣App 2016最火前端框架(17h) 第六章學(xué)習(xí)總結(jié)

1. @2x.png和@3x.png圖片的scss樣式寫法。

@mixin bg-image($url){
  background-image: url($url + "@2x.png")
  @media (-webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3){
    background-image: url($url + "@3x.png")
  }
}

2. 自己親自動手寫的Icon組件洪碳。

組件目錄結(jié)構(gòu)如下:


Icon.vue

<template>
  <span class="icon" :class="['icon_'+kind, iconCls]"></span>
</template>

<script type="text/ecmascript-6">
  export default {
    data() {
      return {
        classMap: ['decrease', 'discount', 'special', 'invoice', 'guarantee']
      }
    },
    props: {
      iconClsNum: {
        type: Number,
        required: true
      },
      kind: {
        type: Number,
        default: 1
      }
    }递览,
    computed: {
      iconCls() {
        return this.classMap[this.iconClsNum]
      }
    }
  }
</script>

<style lang="scss">
  @import "../../common/scss/mixin";
  .icon {
    display: inline-block;
    vertical-align: top;
    background-repeat: no-repeat;
    &.icon_1 {
      width: 12px;
      height: 12px;
      background-size: 12px 12px;
      &.decrease {
        @include bg-image('img/decrease_1');
      }
      &.discount {
        @include bg-image('img/discount_1');
      }
      &.guarantee {
        @include bg-image('img/guarantee_1');
      }
      &.invoice {
        @include bg-image('img/invoice_1');
      }
      &.special {
        @include bg-image('img/special_1');
      }
    }
    &.icon_2 {
      width: 16px;
      height: 16px;
      background-size: 16px 16px;
      &.decrease {
        @include bg-image('img/decrease_2');
      }
      &.discount {
        @include bg-image('img/discount_2');
      }
      &.guarantee {
        @include bg-image('img/guarantee_2');
      }
      &.invoice {
        @include bg-image('img/invoice_2');
      }
      &.special {
        @include bg-image('img/special_2');
      }
    }
    &.icon_3 {
      width: 12px;
      height: 12px;
      background-size: 12px 12px;
      &.decrease {
        @include bg-image('img/decrease_3');
      }
      &.discount {
        @include bg-image('img/discount_3');
      }
      &.guarantee {
        @include bg-image('img/guarantee_3');
      }
      &.invoice {
        @include bg-image('img/invoice_3');
      }
      &.special {
        @include bg-image('img/special_3');
      }
    }
    &.icon_4 {
      width: 16px;
      height: 16px;
      background-size: 16px 16px;
      &.decrease {
        @include bg-image('img/decrease_4');
      }
      &.discount {
        @include bg-image('img/discount_4');
      }
      &.guarantee {
        @include bg-image('img/guarantee_4');
      }
      &.invoice {
        @include bg-image('img/invoice_4');
      }
      &.special {
        @include bg-image('img/special_4');
      }
    }
  }
</style>

引用方法如下

<div v-if="seller.supports" class="support">
  <icon :kind="1" :iconClsNum="seller.supports[0].type"></icon>
   <span class="text">{{seller.supports[0].description}}</span>
</div>

3. Sticky footers布局。

Sticky footers的概括如下:如果頁面內(nèi)容不夠長的時候偶宫,頁腳塊粘貼在視窗底部非迹;如果內(nèi)容足夠長時,頁腳塊會被內(nèi)容向下推送纯趋。關(guān)注詳情憎兽,可參考 CSS秘密花園: Sticky footers冷离。
在sell app中纯命,使用的sticky footers的技術(shù)要點匯總?cè)缦隆?br> sell app 中html代碼如下

<div class="detail ">
  <div class="detail-wrapper clearfix">
    <div class="detail-main">
    </div>
  </div>
  <div class="detail-close">
    <i class="icon-close"></div>
  </div>
</div>

sell app中scss代碼如下

.detail{
  position: fixed;
  z-index: 100;
  top: 0 ;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(7, 17, 27, .8);
  overflow: auto;
  .detail-wrapper{
    min-height: 100%;
    .detail-main{
      margin-top: 64px;
      padding-bottom: 64px;
    }
  }
  .detail-close{
    position: relative;
    margin-top: -64px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    clear: both;
  }
}

sell app 中使用的sticky footer的關(guān)鍵技術(shù)點是 .detail 樣式中 w100% ,h100% ,overflow: auto;.detail-wrapper 加上一個清除浮動的.clearfix并且給它設(shè)置一個最小高度100%西剥。.detail-main樣式里要預(yù)留一個padding-bottom: 64px。在.detail-close樣式里通過設(shè)置position:relative;margin-top: -64px;來實現(xiàn)亿汞。以上代碼是我理解后在簡書里一氣呵成默敲出來的瞭空。

4. 評星組件。

組件目錄結(jié)構(gòu)

Star.vue 源碼如下(以下所有代碼憑借記憶和理解后逐字敲打完成疗我,中間過程沒有看一眼源碼,敲打間幾乎沒有停頓咆畏。目錄結(jié)構(gòu)教視頻中的略有不同,樣式做了進(jìn)一步一點點的優(yōu)化):

<template>
  <div class="star" :class="starType">
    <span class="star-item" v-for="(itemClass, index) in itemClasses" :class="itemClass" :key="index"></span>
  </div>
</template>

<script type="text/ecmascript-6">
  const LENGTH = 5
  const CLS_ON = 'on'
  const CLS_OFF = 'off'
  const CLS_HALR = 'half'
  export default {
    props: {
      size: {
        type: Number
      },
      scores: {
        type: Number
      }
    },
    computed: {
      starType() {
        return 'star-' + this.size
      },
      itemClasses() {
        let result = []
        let score = Math.floor(this.scores * 2) / 2
        let hasDecimal = score % 1 !== 0
        let integer = Math.floor(score)
        for (let i = 0; i < integer; i++) {
          result.push(CLS_ON)
        }
        if (hasDecimal) {
          result.push(CLS_HALR)
        }
        while (result.length < LENGTH) {
          result.push(CLS_OFF)
        }
        return result
      }
    }
  }
</script>

<style lang="scss">
  @mixin bg-image($url) {
    background-image: url($url + '@2x.png');
    @media (-webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {
      background-image: url($url + '@3x.png');
    }
  }

  .star {
    font-size: 0;
    .star-item {
      display: inline-block;
      background-repeat: no-repeat;
      &:last-child {
        margin-right: 0;
      }
    }
    &.star-24 {
      .star-item {
        width: 10px;
        height: 10px;
        background-size: 10px 10px;
        margin-right: 3px;
        &.on {
          @include bg-image('img/star24_on')
        }
        &.off {
          @include bg-image('img/star24_off')
        }
        &.half {
          @include bg-image('img/star24_half')
        }
      }
    }
    &.star-36 {
      .star-item {
        width: 15px;
        height: 15px;
        background-size: 15px 15px;
        margin-right: 6px;
        &.on {
          @include bg-image('img/star36_on')
        }
        &.off {
          @include bg-image('img/star36_off')
        }
        &.half {
          @include bg-image('img/star36_half')
        }
      }
    }
    &.star-48 {
      .star-item {
        width: 20px;
        height: 20px;
        background-size: 20px 20px;
        margin-right: 22px;
        &.on {
          @include bg-image('img/star48_on')
        }
        &.off {
          @include bg-image('img/star48_off')
        }
        &.half {
          @include bg-image('img/star48_half')
        }
      }
    }
  }
</style>

使用時可以通過 <div class="star-wrapper"></div> 包裹來控制外層樣式吴裤。

5. Title組件旧找。

Title.vue:

<template>
  <div>
    <div class="title">
      <div class="line"></div>
      <div class="text">{{cont}}</div>
      <div class="line"></div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      cont: {
        type: String,
        required: true
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import '../../common/scss/mixin';
  .title{
    display: flex;
    .line{
      flex: 1;
      position: relative;
      top: -6px;
      @include border-bottom-1px(rgba(255, 255, 255, .2));
    }
    .text{
      font-size: 14px;
      line-height: 14px;
      font-weight: 700;
      padding: 0 12px;
    }
  }
</style>

使用時,可以通過 <div class="title-wrapper"> <v-title cont="優(yōu)惠信息"></v-title> </div> 外層的.title-wrapper控制外層樣式麦牺。.title-wrapper{ margin: 28px 36px 24px; }钮蛛。因為,cont接收的type被限制成String剖膳。所以在給cont賦值時魏颓,因為給的直接是字符串,所以不可以給cont加 : 賦值吱晒。

6. WebStorm快捷鍵 command + alt + t 可以在外層寫包裹的代碼甸饱。

7. transition動畫÷乇簦可以參考transition詳解柜候。

7.1 使用方法: transtion包裹動畫塊區(qū)域。然后躏精,再寫 .fade-enter . fade-enter-active .fade-leave-active .fade-leave-to的樣式。
scss代碼塊如下:

...
opacity: 1;
background-color: rgba(7, 17, 27, .8);
&.fade-enter,
&.fade-leave-to{
        opacity: 0;
        background-color: rgba(7, 17, 27, 0);
}
&.fade-enter-active,
&.fade-leave-active{
   transition: all .5s;
}
...
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末鹦肿,一起剝皮案震驚了整個濱河市矗烛,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌箩溃,老刑警劉巖瞭吃,帶你破解...
    沈念sama閱讀 219,490評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異涣旨,居然都是意外死亡歪架,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評論 3 395
  • 文/潘曉璐 我一進(jìn)店門霹陡,熙熙樓的掌柜王于貴愁眉苦臉地迎上來和蚪,“玉大人止状,你說我怎么就攤上這事≡芘” “怎么了怯疤?”我有些...
    開封第一講書人閱讀 165,830評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長催束。 經(jīng)常有香客問我集峦,道長,這世上最難降的妖魔是什么抠刺? 我笑而不...
    開封第一講書人閱讀 58,957評論 1 295
  • 正文 為了忘掉前任塔淤,我火速辦了婚禮,結(jié)果婚禮上速妖,老公的妹妹穿的比我還像新娘高蜂。我一直安慰自己,他們只是感情好买优,可當(dāng)我...
    茶點故事閱讀 67,974評論 6 393
  • 文/花漫 我一把揭開白布妨马。 她就那樣靜靜地躺著,像睡著了一般杀赢。 火紅的嫁衣襯著肌膚如雪烘跺。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,754評論 1 307
  • 那天脂崔,我揣著相機與錄音滤淳,去河邊找鬼。 笑死砌左,一個胖子當(dāng)著我的面吹牛脖咐,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播汇歹,決...
    沈念sama閱讀 40,464評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼屁擅,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了产弹?” 一聲冷哼從身側(cè)響起派歌,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎痰哨,沒想到半個月后胶果,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,847評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡斤斧,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,995評論 3 338
  • 正文 我和宋清朗相戀三年早抠,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片撬讽。...
    茶點故事閱讀 40,137評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡蕊连,死狀恐怖悬垃,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情咪奖,我是刑警寧澤盗忱,帶...
    沈念sama閱讀 35,819評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站羊赵,受9級特大地震影響趟佃,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜昧捷,卻給世界環(huán)境...
    茶點故事閱讀 41,482評論 3 331
  • 文/蒙蒙 一闲昭、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧靡挥,春花似錦序矩、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至毒返,卻和暖如春租幕,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背拧簸。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評論 1 272
  • 我被黑心中介騙來泰國打工劲绪, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人盆赤。 一個月前我還...
    沈念sama閱讀 48,409評論 3 373
  • 正文 我出身青樓贾富,卻偏偏與公主長得像,于是被迫代替她去往敵國和親牺六。 傳聞我的和親對象是個殘疾皇子颤枪,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,086評論 2 355