一,城市选择页面路由配置                                                                                                            

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"></span>
</div>
</router-link>

二,城市选择

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

<template>
<div class="header">
<div class="header-left">
<div class="iconfont back-icon"></div>
</div>
<div class="header-input">
<span class="iconfont"></span>输入城市/景点/游玩主题
</div>
<router-link to="/city">
<div class="header-right">
城市<span class="iconfont arrow-right"></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>

目前效果:

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

Vue2.5开发去哪儿网App 城市列表开发的更多相关文章

  1. Vue2.5开发去哪儿网App 城市列表开发之 兄弟组件间联动及列表性能优化

    一,  兄弟组件间联动 1.  点击城市字母,左侧对应显示 给遍历的 字母 添加一个点击事件: Alphabet.vue @click="handleLetterClick" ha ...

  2. Vue2.5开发去哪儿网App 城市列表开发之 Vuex实现数据共享及高级使用

    一,数据共享 1.  安装: npm install vuex --save 2. 在src目录下 新建state文件夹,新建index.js文件 3. 创建一个 store import Vue f ...

  3. Vue2.5开发去哪儿网App 详情页面开发

    一,banner 图的设计 1. 新建detail的路由 import Detail from '@/pages/detail/Detail' ...... { path: '/detail', na ...

  4. Vue2.5 开发去哪儿网App

    Vue2.5开发去哪儿网App 技术栈和主要框架

  5. Vue2.5开发去哪儿网App 从零基础入门到实战项目

    第1章 课程介绍本章主要介绍课程的知识大纲,学习前提,讲授方式及预期收获. 1-1 课程简介 试看第2章 Vue 起步本章将快速讲解部分 Vue 基础语法,通过 TodoList 功能的编写,在熟悉基 ...

  6. Vue2.5开发去哪儿网App 搜索功能完成

    效果展示: Search.vue: <div class="search-content" ref="search" v-show="keywo ...

  7. Vue2.5开发去哪儿网App 首页开发

    主页划 5 个组件,即 header  icon  swiper recommend weekend 一. header区域开发 1. 安装 stylus npm install stylus --s ...

  8. Vue2.5开发去哪儿网App 第五章笔记 上

    1.css动画原理 .fade-enter{ opacity: 0; } .fade-enter-active{ transition: opacity 2s; } .fade-leave-to{ o ...

  9. Vue2.5开发去哪儿网App 第五章笔记 下

    1. 多个元素或组件的过渡 多个元素的过渡: <style> .v-enter,.v-leace-to{ opacity: 0; } .v-enter-active,.v-leave-ac ...

随机推荐

  1. C++航空系统

    /* * SHA-256 implementation, Mark 2 * * Copyright (c) 2010,2014 Ilya O. Levin, http://www.literateco ...

  2. C中的volatile用法[转载]

    volatile 影响编译器编译的结果,指出,volatile 变量是随时可能发生变化的,与volatile变量有关的运算,不要进行编译优化,以免出错,(VC++ 在产生release版可执行码时会进 ...

  3. 使用vue,react,angular等框架和不使用框架使用jquery的优缺点

    jquery和vue react等框架有着本质上的区别,从jquery到vue.react 或者说是到mvvm的转变,是一个思想的转变,是将原有的直接操作dom的思想转变到操作数据上去. vue更关注 ...

  4. i2c设备驱动注册

      Linux I2C设备驱动编写(二) 原创 2014年03月16日 23:26:50   在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c ...

  5. PHP实现视频文件上传完整实例

    这篇文章主要介绍了PHP实现视频文件上传的技巧,包含了PHP配置信息的设计及大文件的处理,需要的朋友可以参考下    本文以一个完整实例的形式实现了视频文件上传的功能.虽然是比较基础的应用,仍有一定的 ...

  6. 在window平台下,自己DIY编译OpenSSL,Libcurl ,来支持HTTPS传输协议

    1 缘起 原来就了解些libcurl,一直没有机会在项目实际使用libcurl.   恰好最近一个云存储的项目,服务器使用openstack 恰好我负责现在的一个云存储SDK c++版本的开发中. 与 ...

  7. 手把手教Electron+vue的使用

    .现如今前端框架数不胜数,尤其是angular.vue吸引一大批前端开发者,在这个高新技术快速崛起的时代,自然少不了各种框架的结合使用.接下来是介绍electron+vue的结合使用. 2.Elect ...

  8. (转)转一份在 51testing 上的讨论——如何测试一个门户网站是否可以支持10万用户同时在线?

    转自:http://www.cnblogs.com/jackei/archive/2006/11/16/561846.html 这个帖子的内容比较典型,大家有兴趣可以也思考一下. 先是楼主提出问题: ...

  9. java基础-day24

    第01天 java基础加强 今日内容介绍 u Junit单元测试及反射概述 u 反射操作构造方法.成员方法.成员属性 u properties的基本操作 u 综合案例 第1章   Junit单元测试及 ...

  10. Codeforces822 A I'm bored with life

    A. I'm bored with life time limit per test 1 second memory limit per test 256 megabytes input standa ...