Vue2.5開發去哪兒網App 首頁開發

来源:https://www.cnblogs.com/donghaoblogs/archive/2019/02/25/10431485.html
-Advertisement-
Play Games

主頁劃 5 個組件,即 header icon swiper recommend weekend 一. header區域開發 1. 安裝 stylus npm install stylus --save cnpm install stylus-loader --save 2. 編寫樣式 3. 添加i ...


主頁劃 5 個組件,即 header  icon  swiper recommend weekend

一. header區域開發

1. 安裝 stylus 

npm install stylus --save

cnpm install stylus-loader --save

2. 編寫樣式

<template>
  <div class="header">
    <div class="header-left">返回</div>
    <div class="header-input">
      輸入城市/景點/游玩主題
    </div>
    <div class="header-right">城市</div>
  </div>
</template>

<script>
export default {
  name: 'HomeHeader'
}
</script>
<!--組件樣式,不影響其他組件-->
<!--1rem = html front-size = 50px-->
<style lang="stylus" scoped>
.header
  display flex
  line-height:.86rem
  background: #00bcd4
  color: #fff
  .header-left
    float:left
    width :.64rem
  .header-input
    flex: 1
    height: .64rem
    line-height: .64rem
    margin-top: .12rem
    margin-left: .2rem
    padding-left: .2rem
    color: #ccc
    background: #fff
    border-radius: .1rem
  .header-right
    min-width: 1.04rem
    padding: 0 .1rem
    float: right
    text-align: center
    color: #ffffff
</style>

3. 添加icon

 進入https://www.iconfont.cn 添加返回,搜索,下箭頭的icon,添加至項目,並且下載到本地

新建iconfront 目錄,將一下4個文件移動到該目錄

將iconfront.css移動到styles目錄

進入 Build 下的  webpack.base.conf.js 第38行,添加目錄搜索路徑

  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'styles':resolve('src/assets/styles')
    }
  }

main.js  引入 iconfront文件  

import 'styles/iconfont.css'

頁面使用:

  <div class="header">
    <div class="header-left">
      <div class="iconfont back-icon">&#xe606;</div>
    </div>
    <div class="header-input">
      <span class="iconfont">&#xe6aa;</span>輸入城市/景點/游玩主題
    </div>
    <div class="header-right">
      城市<span class="iconfont arrow-right">&#xe638;</span>
    </div>
  </div>

定義css  變數:styles文件夾新建   varibles.styl

定義變數:$bgColor = #00bcd4
<style lang="stylus" scoped>
 @import "~styles/varibles.styl"
 .header
  display flex
  line-height:.86rem
  background: $bgColor
<template>
  <div class="header">
    <div class="header-left">
      <div class="iconfont back-icon">&#xe606;</div>
    </div>
    <div class="header-input">
      <span class="iconfont">&#xe6aa;</span>輸入城市/景點/游玩主題
    </div>
    <div class="header-right">
      城市<span class="iconfont arrow-right">&#xe638;</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HomeHeader'
}
</script>
<!--組件樣式,不影響其他組件-->
<!--1rem = html front-size = 50px-->
<style lang="stylus" scoped>
 @import "~styles/varibles.styl"
 .header
  display flex
  line-height:.86rem
  background: $bgColor
  color: #fff
  .header-left
    margin-left: 0.1rem
    float:left
    width :.64rem
  .header-input
    padding-left:.2rem
    .back-icon
      text-align center
      font-size .4rem
    flex: 1
    height: .64rem
    line-height: .64rem
    margin-top: .12rem
    margin-left: .2rem
    padding-left: .2rem
    color: #ccc
    background: #fff
    border-radius: .1rem
  .header-right
    .arrow-right
      font-size .3rem
      margin-left -.05rem
    min-width: 1.04rem
    padding: 0 .1rem
    float: right
    text-align: center
    color: #ffffff
</style>
Header.vue

效果:

二. 首頁輪播圖

在GIthub 上新建 index-swiper分支

拉到本地: git pull

 git checkout index-swiper  (Your branch is up to date with 'origin/index-swiper'.)

使用 

vue-awesome-swiper

使用地址:https://github.com/surmon-china/vue-awesome-swiper

安裝:npm install [email protected] --save

導入使用:

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

Vue.use(VueAwesomeSwiper)

Swiper.vue:

  <div class="wrapper">
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for ='item of swiperList' :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>

swiper配置項:
swiperOption: {
loop: true, 迴圈
pagination: '.swiper-pagination' 小圓圈
}
數據:
swiperList: [
{
id: '001',
imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20191/f0e1f1fedae3e7da7eeda416d08c0911.jpg_750x200_19683e97.jpg'
},
{
id: '001',
imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20191/61e0c45bd6f46af63f03fc19af63fd57.jpg_750x200_21f214c6.jpg'
}
]

小圓點樣式修改:
.wrapper >>> .swiper-pagination-bullet-active  對swiper組件樣式的穿透
background: #ffffff

Swiper中文官網:    https://www.swiper.com.cn/api/pagination/bulletElement.html

代碼提交:

git add .      

 git commit -m 'change'

 git push

git checkout master

git merge origin/index-swiper

效果:

<template>
  <div class="wrapper">
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for ='item of swiperList' :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  data () {
    return {
      swiperOption: {
        loop: true,
        pagination: '.swiper-pagination'
      },
      swiperList: [
        {
          id: '001',
          imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20191/f0e1f1fedae3e7da7eeda416d08c0911.jpg_750x200_19683e97.jpg'
        },
        {
          id: '001',
          imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20191/61e0c45bd6f46af63f03fc19af63fd57.jpg_750x200_21f214c6.jpg'
        }
      ]
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background: #ffffff
  .wrapper
  overflow hidden
    width 100%
    height 0
    padding-bottom 31.25%
    .swiper-img
      width 100%
</style>
Swiper.vue

三,圖標區域頁面佈局

新建index-iocns分支

git pull      

git checkout index-icons

新建Icon.vue

代碼:

<template>
  <div class="icons">
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div>
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div>
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div>
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div>
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div>
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div>
    <div class="icon">
      <div class="icon-img">
        <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
      </div>
      <p class="icon-desc">熱門景點</p>
    </div><div class="icon">
    <div class="icon-img">
      <img class="icon-img-content" src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
    </div>
    <p class="icon-desc">熱門景點</p>
  </div>

  </div>
</template>

<script>
export default {
  name: 'HomeIcons'
}
</script>

<style scoped lang="stylus">
  @import "~styles/varibles.styl"
  .icons
    height:0
    width 100%
    padding-bottom 50%
    overflow hidden
    .icon
      position relative
      overflow hidden
      float left
      height 0
      width 25%
      padding-bottom 25%
      .icon-img
        position absolute
        top 0
        box-sizing border-box
        padding .1rem
        left 0
        right 0
        bottom .44rem
        .icon-img-content
          display block
          margin 0 auto
          height 100%
    .icon-desc
      position absolute
      bottom 0
      line-height .44rem
      height .44rem
      left 0
      right 0
      color $darkTextColor
      text-align center
</style>
Icon.vue
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import fastClick from 'fastclick'
import 'styles/reset.css'
import 'styles/border.css'
import 'styles/iconfont.css'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

Vue.config.productionTip = false
fastClick.attach(document.body)
Vue.use(VueAwesomeSwiper)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
main.js

效果:

四,圖標區域邏輯實現

添加swiper 組件

  
每頁展示8個,超過時進行分頁,可以滾動
<swiper :options="swiperOption"> <swiper-slide v-for="( page,index) of Mypages" :key="index"> <div class="icons"> <div class="icon" v-for="item in page" :key="item.id"> <div class="icon-img"> <img class="icon-img-content" :src="item.imgUrl" alt=""> </div> <p class="icon-desc">{{item.desc}}</p> </div> </div> </swiper-slide> </swiper>

添加計算屬性:

    Mypages: function () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        console.log(pages)
        pages[page].push(item)
      })
      return pages
    }
<template>
  <swiper :options="swiperOption">
    <swiper-slide v-for="( page,index) of Mypages" :key="index">
      <div class="icons">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </div>
    </swiper-slide>
  </swiper>
</template>

<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      swiperOption: {
      },
      iconList: [
        {
          id: '0001',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '景點門票'
        }, {
          id: '0002',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
          desc: '一日游'
        }, {
          id: '0003',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
          desc: '北京必游'
        }, {
          id: '0004',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png',
          desc: '溜娃兒'
        }, {
          id: '0005',
          imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20191/0334cf5430b9b5505fd79e2b8d7e8670.png',
          desc: '爬長城'
        }, {
          id: '0006',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png',
          desc: '故宮'
        }, {
          id: '0007',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png',
          desc: '茶館相聲'
        }, {
          id: '0008',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/fc/b10a6b2e4f0fe102.png',
          desc: '北京滑雪'
        }, {
          id: '0009',
          imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/76/eb88861d78fb9902.png',
          desc: '動植物園'
        }
      ]
    }
  },
  computed: {
    Mypages: function () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        console.log(pages)
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped lang="stylus">
  @import "~styles/varibles.styl"
  @import "~styles/mixins.styl"
  .icons
    height:0
    width 100%
    padding-bottom 50%
    overflow hidden
    .icon
      position relative
      overflow hidden
      float left
      height 0
      width 25%
      padding-bottom 25%
      .icon-img
        position absolute
        top 0
        box-sizing border-box
        padding .1rem
        left 0
        right 0
        bottom .44rem
        .icon-img-content
          display block
          margin 0 auto
          height 100%
    .icon-desc
      position absolute
      bottom 0
      line-height .44rem
      height .44rem
      left 0
      right 0
      color $darkTextColor
      text-align center
      ellipsis()
</style>
View Code

效果:

第一頁:

第二頁:

代碼提交:

git add .     

git commit -m 'add icons'

git push

git checkout master

git merge origin/index-icons

 git push

五,推薦組件開發

github上 新建index-recommend分支

git pull      

git checkout index-recommend

熱門推薦組件:

在  pages/home/components/下  新建Recommend.vue

<template>
  <div>
    <div class="title">
      熱銷推薦
    </div>
    <ul>
      <li class="item" v-for="item in imgList" :key="item.id">
        <div class="item-img-wrapper">
          <img class="item-img" :src="item.imgUrl" alt="">
        </div>
        <div class="item-info">
          <p class="item-title">{{item.title}}</p>
          <p class="item-desc">{{item.desc}}</p>
          <button class="item-button">查看詳情</button>
        </div>
      </li>
    </ul>
  </div>
</template>
<template>
  <div>
    <div class="title">
      熱銷推薦
    </div>
    <ul>
      <li class="item" v-for="item in imgList" :key="item.id">
        <div class="item-img-wrapper">
          <img class="item-img" :src="item.imgUrl" alt="">
        </div>
        <div class="item-info">
          <p class="item-title">{{item.title}}</p>
          <p class="item-desc">{{item.desc}}</p>
          <button class="item-button">查看詳情</button>
        </div>
      
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 什麼是閉包? 簡單理解,當在一個函數的外部訪問函數內部定義的變數的時候就會形成一個閉包,由這個理解可以知道,當一個函數執行完成的時候,一般情況下,其作用域會被銷毀,其內部定義的變數也會變得不可訪問,所以閉包打破了這個現象。閉包造成一個函數執行完成之後,其創建的作用域不會被銷毀,因為它被函數外部的對象 ...
  • 年三十時 vue2.6 發佈,向 3.0 看齊,說明 3.0 不遠了。作為開發者也應該為vue3.0 做點準備。首先是把 vue-cli 升級到 3.x ,在這記錄下 vue-cli2.x 升級 vue-cli3.x 中遇見(將來)遇見的問題。 1、安裝 vue-cli3.x 如果希望還保留 vue ...
  • // canvas畫圖 // 顏色漸變 var grd = draw.createLinearGradient(0,0,175,50); grd.addColorStop(0, '#f00'); grd.addColorStop(0.5, '#0f0'); grd.addColorStop(1.0, ...
  • 個人很喜歡谷歌的material design,很喜歡但是沒有動手弄過,今天想動手操作一下Floating Action Button菜單,網上有很多種:圓形、扇形、射線、直線等。我想在一個例子中用到這幾種展現形式,觸發按鈕在不同的位置,菜單用不同的方式展示…… 基於這種需求,開始著手準備,此時遇到 ...
  • Promise 是 JavaScript 非同步編程中的重要概念,是目前較為流行的 JavaScript 非同步編程解決方案之一。它最早由社區提出和實現,ES6 將其寫進了語言標準,統一了用法,原生提供了 對象。 Promise 的基本概念 一個 有以下幾種狀態: pending: 初始狀態,既不是成功 ...
  • var MyModules = (function Manager(){ // 保存方法 var modules = {}; // 傳方法名,參數,方法 方法的參數由deps提供 function define(name, deps, impl) { // 將模塊中的方法給deps 作為下一個函數的... ...
  • 使用vscode開發vue項目的時候,從遠端拉下一個新的項目後,安裝完依賴後跑起項目時,發現直接報了一堆語法錯誤:包括換行、空格、單雙引號、分號等各種格式問題 ...
  • 葵花寶典: 【1】相鄰的2個margin值會疊加在一起。 【2】子元素設定的margin值會影響父元素。 在標準瀏覽器下(FireFox,Chrome,Opera,Safari)會有問題。IE下一般表現良好。 原因是:一個盒子如果沒有上補白(padding-top)和上邊框(border-top)那 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...