vue2.0_餓了麼——購物車元件
購物車元件:shopcart.vue
/*
*編輯於2017年12月14日
*加油!
*/
<template> <div class="shopcart"> <div class="content"> <!-- 購物車左側部分開始 --> <div class="content-left"> <!-- 放logo的部分開始 --> <div class="logo-wrapper"> <!-- 放購物車圖示的div --> <div class="logo" :class="{'highlight':totalCount>0}"> <span class="cart" > <!-- 使用font-awesome裡面的fa-shopping-cart,要先npm install font-awesome,再在main.js引入font-awesome.css --> <!-- 判斷數量大於0就繫結&.highLight樣式高亮 --> <i class="fa fa-shopping-cart fa-2x" :class="{'highlight':totalCount>0}"></i> </span> </div> <!-- 購物車左上角的數量小表示,v-show用來控制是否顯示,totalCount>0時顯示這個div --> <div class="num" v-show="totalCount>0">{{totalCount}}</div> </div> <!-- 放logo的部分結束 --> <!-- 放總價的部分,用:class新增高亮樣式,價格大於0時新增&.highlight --> <div class="price" :class="{'highlight':totalPrice>0}">¥{{totalPrice}}</div> <!-- 配送費 --> <div class="desc">另需配送費{{deliveryPrice}}</div> </div> <!-- 購物車左側部分結束 --> <!-- 購物車右側部分開始 --> <div class="content-right"> <!-- payDesc分3種情況,對應2不同樣式payClass --> <div class="pay" :class="payClass"> {{payDesc}} </div> </div> <!-- 購物車右側部分結束 --> </div>> </div> </template> <script type="text/ecmascript-6"> export default { props: { // 父元件向字子元件傳遞資料 // 購物車狀態由selectFoods這個陣列決定(自定義),陣列每個值表示當前該商品的總價(price*count) // selectFoods預設值為return:[]; selectFoods: { type: Array, default() { return [ // 這個是測試資料,可以註釋掉 { price: 5, count: 5 } ]; // 陣列,每個值表示商品總價 } }, deliveryPrice: { // 配送費 type: Number, default: 3 }, minPrice: { // 起送價錢 type: Number, default: 10 } }, computed: { // 計算屬性 totalPrice() { // 根據selectFoods陣列計算總價 let total = 0; // 定義總價total = 0 this.selectFoods.forEach((food) => { // 遍歷陣列,對每個food的food.price和food.count相乘求和 total += food.price * food.count; }); return total; // 返回總價 }, totalCount() { // 根據selectFoods陣列計算數量 let count = 0; this.selectFoods.forEach((food) => { count += food.count; // 每種food的count相加 }); return count; // 返回總數量 }, payDesc() { // 購物車右側描述詳情 // 用反引號(波浪線下面)不用拼接字串,返回{} if (this.totalPrice === 0) { // 當前總價為0顯示:¥${this.minPrice}元起送 return `¥${this.minPrice}元起送`; } else if (this.totalPrice < this.minPrice) { let diff = this.minPrice - this.totalPrice; // 計算距離起送價的差價 return `還差¥${diff}元起送`; // 返回還差¥${diff}元起送 } else { return `去結算`; // 滿足起送價格條件顯示去結算 } }, payClass() { if (this.totalPrice < this.minPrice) { return 'not-enough'; // 小於起送價,返回not-enough,:class="not-enough" } else { return 'enough'; // 返回enough,:class="enough" } } } }; </script> <style lang="stylus" ref="stylesheet/stylus"> .shopcart position: fixed z-index: 50 left: 0 bottom: 0 height: 40px background: black width: 100% .content display: flex background: #141d27 .content-left flex: 1 .logo-wrapper display: inline-block position: relative top: -10px margin: 0 12px padding: 6px width: 56px height:56px box-sizing: border-box border-radius: 50% vertical-align: center background: #141d27 .logo width: 100% height: 100% border-radius: 50% background: #2b343c &.highlight background: rgb(0, 160, 220) .fa margin-left: 4px margin-top: 5px color: #898989 &.highlight color: #fff .num position: absolute top: 0 left: 0 width: 24px height: 16px line-height: 16px text-align: center background: rgb(240, 20, 20) color: #fff font-size: 9px font-weight: 700 box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.4) border-radius: 6px .price display: inline-block line-height: 24px font-size: 12px color: rgb(255, 255, 255, 0.4) vertical-align: top padding-right: 12px box-sizing: border-box border-right: 1px solid rgba(255, 255, 255, 0.1) font-weight: 700 padding-top: 8px &.highlight color: #fff font-size: 16px .desc flex: 0 0 100px display: inline-block height: 50px line-height: 24px font-size: 12px font-weight: 700 text-align: center width: 100px color: rgba(255, 255, 255, 0.4) .content-right flex: 0 0 110px width: 120px .pay height: 48px line-height: 48px text-align: center font-size: 16px font-weight: 700 color: rgba(255, 255, 255, 0.4) background: #2b333b &.not-enough background: #2b333b &.enough background: #00b43c color: #fff </style>
相關推薦
vue2.0_餓了麼——購物車元件
購物車元件:shopcart.vue/**編輯於2017年12月14日*加油!*/<template> <div class="shopcart"> <div class="content"> <!-- 購物車左側
VUE2.0 餓了麼學習筆記(10)加減號元件cartcontrol
建立cartcontrol元件,元件關聯到food的相關屬性,價格,數量等,所以元件要props父元件goods傳過來的food資料 export default { //父元件傳過來的,接收一個props屬性來計算商品的個數,food.count,去goods元件
vue2.0餓了麼--header資料獲取後進行header元件的編寫
首先我們通過props屬性接受到父元件App.vue傳過來的資料 export default { //:seller = "seller" props接收傳過來的seller物件 props: { seller: { type: Object
vue2.0 餓了麼學習筆記(14)food.vue的實現
點選food展開詳情頁food.vue的實現1)新建good資料夾和good.vue,設定樣式,並接受一個被選中的food props: { //接收傳入的food food: { type: Object }
仿餓了麼購物車效果(UI效果)
右列表標題懸停 左右列表滑動時聯動 新增購物車時動畫效果 右列表標題懸停&左右列表滑動時聯動 gradle新增依賴 compile 'se.emilsjolander:stickylisthead
Vuex仿餓了麼購物車功能
餓了麼購物車功能 今天通過Vuex完成了基本的購物車功能,對Vuex的store和mutation有了進一步認識。 實現購物車所需要的資料 store作為可以全域性訪問的資料倉庫,滿足了我們在任意一個元件使用資料的需求。所以,我預先在store裡宣告三個變數:f
Android開發之貝塞爾曲線進階篇(仿直播送禮物,餓了麼購物車動畫)
又是一年畢業季,今年終於輪到我了,最近一邊忙著公司的專案,一邊趕著畢設和論文,還私下和朋友搞了些小外包,然後還要還抽出時間寫部落格,真是忙的不要不要的。 好了,言歸正傳,前幾天寫了一篇關於貝塞爾曲線的基礎篇,如果你對貝塞爾曲線還不是很瞭解,建議你先去閱讀下:Android開發之貝塞爾曲線初體驗 ,今天這篇文
Element-UI餓了麼時間元件控制元件按月份週日期,開始時間結束時間範圍限制引數
在日常開發中,我們會遇到一些情況,在使用Element-UI 限制使用者的日期時間範圍的選擇控制(例如:查詢訊息開始和結束時間,需要限制不能選擇今天之後的時間)。 看了網上的一些文件,零零散散、各式各樣的都是簡單的吧程式碼列出來,並沒有詳細的說明各引數的含義,用途,對新手及其不友好。
餓了麼專案---12、父子元件、兄弟元件之間資料通訊與事件派發(關於購物車新增按鈕的動畫)
html程式碼 生成一個動畫小球的div,並且生成五個小球,五個是為了生成一定數量的小球來作為操作使用,按照小球動畫的速度,一般來說五個也可以保證有足夠的小球數量來執行動畫 動畫的內容分別是外層和內
Android 仿餓了麼加入購物車特效控制元件(自定義View實戰)-張旭童-專題視訊課程
Android 仿餓了麼加入購物車特效控制元件(自定義View實戰)—5681人已學習 課程介紹 利用 純自定義View,實現的仿餓了麼加入購物車控制元件,自帶閃轉騰挪動畫的按鈕。課程收益 1 掌握自定義View,打造酷炫控制元件。 2 UI考慮View的
Vue2.x實戰餓了麼專案筆記(一)
mack資料 如果後端介面尚未開發完成,前端開發一般使用mock資料。 注意:新版的vue-cli 自動搭建的build 檔案裡沒有dev-server.js 和 dev-client.js ,因此我們要在webpack.dev.conf.js 裡配置 複製data.json 到sr
Vue2.0餓了嗎的實踐-header元件的實踐
header元件的實現圖: header元件的程式碼: html: <template> <div class="header"> <div class="content-wrapper"> <div
【餓了麼】—— Vue2.0高仿餓了麼核心模組&移動端Web App專案爬坑(一)
前言:學習Vue.js高仿餓了麼課程過程中,總結了這個Web App專案從準備到開發完畢自己覺得很重要的知識點。這一篇主要介紹:專案準備、頁面骨架開發、header元件開發。 專案github地址:https://github.com/66Web/ljq_eleme,歡迎Star。
【餓了麼】—— Vue2.0高仿餓了麼核心模組&移動端Web App專案爬坑(二) 【重點突破】—— 當better-scroll 遇見Vue
前言:上一篇專案總結介紹了頁面骨架的開發、header元件的開發,這一篇主要梳理:商品元件開發、商品詳情頁實現。專案github地址:https://github.com/66Web/ljq_eleme,歡迎Star。 goods
Vue2.0高仿餓了麼核心模組&移動端Web App專案爬坑(一)
原文https://www.cnblogs.com/ljq66/p/9980372.html 前言:學習Vue.js高仿餓了麼課程過程中,總結了這個Web App專案從準備到開發完畢自己覺得很重要的知識點。這一篇主要介紹:專案準備、頁面骨架開發、header元件開發。 專案github地址:
vue餓了麼(三)--goods元件 & shopcart元件
1.goods.vue滾動實現:"better-scroll" 1.package.json中引入"better-scroll"。cnpm install --------》 npm run dev "dependencies": { "axios
vue餓了麼(二)--Sticky footer & start星星元件 & flex浮懸窗小標題
1.Sticky footer佈局 1.何為Sticky footer佈局:不管內容區有多少內容,頁尾始終顯示在螢幕的最下方,當內容區域超過螢幕的高度時。頁尾會始終顯示在頁面的最底部。 <!DOCTYPE html> <html lang="en"> <head
基於vue2+nuxt構建的高仿餓了麼(2018版)
前言 高仿餓了麼,以nuxt作為vue的服務端渲染,適合剛接觸或者準備上vue ssr的同學參考和學習 專案地址如遇網路不佳,請移步國內映象加速節點 效果演示 檢視demo請戳這裡(請用chrome手機模式預覽) 移動端掃描下方二維碼 API介面文件 介面文件地址(基於apidoc) 技術棧 vue2 +
vue餓了麼(四)--cartcontrol元件 & 減號新增滾動動畫transition
1.cartcontrol結構 <template> <div class="cartcontrol"> <transition name="move"> <div class="cart-decrease" v-sho
mvp實現Xrecyclerview的上下拉和購物車功能(仿餓了麼)
首先先匯入咱們的依賴 implementation 'com.android.support:design:28.0.0' implementation 'com.google.code.gson:gson:2.8.5' implementation 'cn.b