Vue2.5開發去哪兒網App 城市列表開發 上

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

1. 在 router目錄下 的 index.js文件中,新增路由 import City from '@/pages/city/City' { path: '/city', name: 'City', component: City } 2. 在city 目錄下新建city文件夾,然後新建 Cit ...


 一,城市選擇頁面路由配置                                                                                                                                                                                                    

1. 在 router目錄下 的 index.js文件中,新增路由


import City from '@/pages/city/City'
{
  path: '/city',
  name: 'City',
  component: City
}

2. 在city 目錄下新建city文件夾,然後新建 City.vue  

<template>
  <div>
 
  </div>
</template>

<script>

export default {
  name: 'City',
  components: {
    
  }
}
</script>

<style lang="stylus" scoped>

</style>

3.在 首頁的城市選擇處,新增router-link 組件

<router-link to="/city">
<div class="header-right">
城市<span class="iconfont arrow-right">&#xe638;</span>
</div>
</router-link>

二,城市選擇                                                                                               

1. header部分  在components 文件中 新增 header.vue

<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>
    <router-link to="/city">
      <div class="header-right">
        城市<span class="iconfont arrow-right">&#xe638;</span>
      </div>
    </router-link>
  </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:$headerHeight
  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>

2. 在components  中新增  Search.vue

<template>
  <div class="search">
    <input type="text" class="search-input" placeholder="輸入城市名或拼音">
  </div>
</template>

<script>
export default {
  name: 'CitySearch'
}
</script>
<!--組件樣式,不影響其他組件-->
<!--1rem = html front-size = 50px-->
<style lang="stylus" scoped>
@import "~styles/varibles.styl"
  .search
    height .72rem
    padding 0 .1rem
    background $bgColor
    .search-input
      padding 0 .1rem
      box-sizing border-box
      height .62rem
      line-height .62rem
      width 100%
      text-align center
      border-radius .06rem
</style>

目錄結構:

  效果:

   三,列表佈局                                                                                                                                                                                                 

1. 在components 中新建List.vue 

<template>
  <div class="list" ref="wrapper">
    <div>
      <div class="area">
        <div class="title border-topbottom">當前城市</div>
        <div class="button-list">
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="title border-topbottom">熱門城市</div>
        <div class="button-list">
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
          <div class="button-wrapper">
            <div class="button">北京</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="title border-topbottom">A</div>
        <div class="item-list">
          <div class="item border-bottom">阿裡爾</div>
          <div class="item border-bottom">阿裡爾</div>
          <div class="item border-bottom">阿裡爾</div>
          <div class="item border-bottom">阿裡爾</div>
          <div class="item border-bottom">阿裡爾</div>
        </div>
      </div>
    </div>
  </div>
</template>

樣式:

  @import "~styles/varibles.styl"
  .border-topbottom
    &:before
      border-color #ccc
    &:after
      border-color #ccc
  .border-bottom
  &:before
    border-color #ccc
  .list
    overflow hidden
    position absolute
    top 1.58rem
    right 0
    bottom 0
    left 0
    .title
      line-height .54rem
      padding-left .2rem
      background #eee
      color #666
      font-size .26rem
    .button-list
      padding .1rem .6rem .1rem .1rem
      overflow hidden
      .button-wrapper
        float left
        padding .1rem
        .button
          text-align center
          margin .1rem
          border .02rem solid #ccc
          border-radius .06rem
          padding .1rem .5rem
    .item-list
      .item
        line-height .76rem
        padding-left .2rem

2. 使用better-scroll  聯級滾動

GIt地址  :https://github.com/ustbhuangyi/better-scroll

安裝: npm install better-scroll

使用:

CityList.vue

<div class="list" ref="wrapper">
<div>
  ......
  </div>
<div>
import BScroll from 'better-scroll'
export default {
  name: 'CityList',
  mounted: function () {
//this.$refs.wrapper獲取dom元素
this.scroll = new BScroll(this.$refs.wrapper)
}
}

 3. 右側字母表

新建  Alphabet.vue

<template>
  <div>
    <ul class="list">
      <li class="item">A</li>
      <li class="item">A</li>
      <li class="item">A</li>
      <li class="item">A</li>
      <li class="item">A</li>
      <li class="item">A</li>
      <li class="item">A</li>
    </ul>
  </div>
</template>

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

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .list
    position absolute
    right 0
    top 1.58rem
    bottom 0
    display flex
    width .4rem
    flex-direction column
    justify-content center
    .item
      text-align center
      line-height .4rem
      color $bgColor
</style>
View Code

目前效果:

4. 動態數據渲染

在static 目錄下新建moc 文件夾,添加city.json文件

地址:https://github.com/1417766861/Vue2.5-App/blob/master/Travel/static/moc/city.json

發送ajax 請求:


import ApiUrl from '@/config/api_url'

......
data () {
return { cities: {}, hotCities: [] } }, methods: { getCityInfo () { axios.get(ApiUrl.api + 'city.json') .then(this.handleGetCityInfoSucc) }, handleGetCityInfoSucc (res) { res = res.data if (res.ret && res.data) { this.cities = res.data.cities this.hotCities = res.data.hotCities } } }, mounted () { this.getCityInfo() }

/src/config/api_url.js

export default {
  api: '/static/moc/'
}

給組件添加數據:

    <city-list :cities="cities" :hotcities="hotCities"></city-list>
    <city-alphabet :cities="cities"></city-alphabet>

遍歷顯示,List.vue

      <div class="area">
        <div class="title border-topbottom">熱門城市</div>
        <div class="button-list">
          <div class="button-wrapper" v-for="city in hotcities" :key="city.id">
            <div class="button">{{city.name}}</div>
          </div>
        </div>
      </div>
      <div class="area" v-for="(city,key) in cities" :key="key">
        <div class="title border-topbottom">{{key}}</div>
        <div class="item-list">
          <div class="item border-bottom" v-for="c in city" :key="c.id">{{c.name}}</div>
        </div>
      </div>

遍歷顯示,Alphabet.vue

    <ul class="list">
      <li class="item" v-for="(item,key) in cities" :key="key">{{key}}</li>
    </ul>

效果:

 

 代碼地址:https://github.com/1417766861/Vue2.5-App


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1. 添加屬性screenHeight 和 timer。 screenHeight: window.innerHeight timer: '' // window.onresize函數頻繁調用時,頁面抖動較大,設定間隔 2. 在mounted 鉤子函數中監聽onresize事件 let that = ...
  • 一、CSS樣式規則 1、基本結構 <html> <head> <style> h1{ color: orange; } </style> </head> <body> </body> </html> 二、font字體 1、字型大小與字體 font-size: 字型大小大小 font-family: 字體 f ...
  • Web概念 JavaWeb 使用java語言開發基於互聯網的項目 軟體架構 C/S架構:Client/Server 客戶端/伺服器 用戶本地有一個客戶端程式,在遠程有一個服務端程式 如QQ,英雄聯盟....... 優點 用戶體驗好 缺點 開發,安裝,部署,維護麻煩 B/S架構:Browser/Ser ...
  • JavaScript: 概念 :一門客戶端腳本語言 運行在客戶端瀏覽器中的,每一個瀏覽器都有一個JavaScript的解析引擎 腳本語言:不需要編譯,直接就可以被瀏覽器解析執行了 功能: 可以用來增強用戶和html頁面的交互過程,用來控制html元素,讓頁面有一些動態效果,增強用戶的體驗 JavaS ...
  • 一 :背景 1.1 測試提出的bug,我查看了一下其他頁面選擇時間的控制項。通過對比發現別人用的glyphicon-arrow-left 爾我用的是 icon-arrow-left 而且百度也沒有找到相關問題的解決辦法。 1.2 對於這種查閱百度也找不到解決的辦法,也只能試試運氣查看源碼(bootst ...
  • Echarts堆積柱狀圖排序是按照堆積柱狀圖的柱子高度進行從大到小(或者從小到大)進行排序,方便查閱各坐標情況。以下是我自己研發的方法,有不對的地方敬請諒解,隨時歡迎指教。 排序後效果如下圖: (1)排序函數,這是一個簡單的冒泡排序,首先計算橫坐標各柱子的和,然後進行簡單的冒泡排序(因為時間緊),可 ...
  • vux VUX 是基於 WeUI 和 Vue.js 的 移動端 UI 組件庫,提供豐富的組件滿足移動端(微信)頁面常用業務需求。 在vue cli中使用步驟如下: 1、安裝: npm i vux S 2、vux2必須配合vux loader使用,並配置build/webpack.base.conf. ...
  • 實現思路: 1、 v model 一個收集所有input(除全選框外)數組checkModel ,vue會動態將其checked為true的input的value值存入數組checkModel里 2 、watch函數來監聽checkModel 屬性,當其長度==input元素時 全選按鈕選中 否則取 ...
一周排行
    -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 ...