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
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...