Vue2.5开发去哪儿网App 城市列表开发
一,城市选择页面路由配置
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>
效果:

Vue2.5开发去哪儿网App 城市列表开发的更多相关文章
- Vue2.5开发去哪儿网App 城市列表开发之 兄弟组件间联动及列表性能优化
一, 兄弟组件间联动 1. 点击城市字母,左侧对应显示 给遍历的 字母 添加一个点击事件: Alphabet.vue @click="handleLetterClick" ha ...
- Vue2.5开发去哪儿网App 城市列表开发之 Vuex实现数据共享及高级使用
一,数据共享 1. 安装: npm install vuex --save 2. 在src目录下 新建state文件夹,新建index.js文件 3. 创建一个 store import Vue f ...
- Vue2.5开发去哪儿网App 详情页面开发
一,banner 图的设计 1. 新建detail的路由 import Detail from '@/pages/detail/Detail' ...... { path: '/detail', na ...
- Vue2.5 开发去哪儿网App
Vue2.5开发去哪儿网App 技术栈和主要框架
- Vue2.5开发去哪儿网App 从零基础入门到实战项目
第1章 课程介绍本章主要介绍课程的知识大纲,学习前提,讲授方式及预期收获. 1-1 课程简介 试看第2章 Vue 起步本章将快速讲解部分 Vue 基础语法,通过 TodoList 功能的编写,在熟悉基 ...
- Vue2.5开发去哪儿网App 搜索功能完成
效果展示: Search.vue: <div class="search-content" ref="search" v-show="keywo ...
- Vue2.5开发去哪儿网App 首页开发
主页划 5 个组件,即 header icon swiper recommend weekend 一. header区域开发 1. 安装 stylus npm install stylus --s ...
- Vue2.5开发去哪儿网App 第五章笔记 上
1.css动画原理 .fade-enter{ opacity: 0; } .fade-enter-active{ transition: opacity 2s; } .fade-leave-to{ o ...
- Vue2.5开发去哪儿网App 第五章笔记 下
1. 多个元素或组件的过渡 多个元素的过渡: <style> .v-enter,.v-leace-to{ opacity: 0; } .v-enter-active,.v-leave-ac ...
随机推荐
- 2018.11.04 NOIP训练 小水塘(并查集)
传送门 这是复习普及组的时候做过的题了. 之前一直觉得很难码没有去做. 现在发现可以用并查集直接水过去. 其实就是把题目中说的连通的部分的面积用带权并查集维护一下就行了. 代码: #include&l ...
- (17)Questioning the universe
https://www.ted.com/talks/stephen_hawking_asks_big_questions_about_the_universe/transcript00:13There ...
- canvas画的时钟
结合几天来学习的canvas的API,终于完成了一个时钟呵呵 html <!doctype html> <html> <head> <meta charset ...
- x86_64汇编调试程序初步
寄存器说明: rdi 存第1个参数(值或地址) rsi 存第2个参数 rdx 存第3个参数 rcx 存第4个参数 r8 存第5个参数 r9 存第6个参数 rax 第1个返回值 rdx 第2个返回值 r ...
- Ng第十四课:降维(Dimensionality Reduction)
14.1 动机一:数据压缩 14.2 动机二:数据可视化 14.3 主成分分析问题 14.4 主成分分析算法 14.5 选择主成分的数量 14.6 重建的压缩表示 14.7 主成分分析法 ...
- (转)MyEclipse10下创建web项目并发布到Tomcat
转自:http://blog.sina.com.cn/s/blog_699d3f1b01012spf.html MyEclipse10下创建web项目并发布到Tomcat 1.软件安装(不作详细描 ...
- java基础-day13
第01天 java面向对象 今日内容介绍 u 继承 u 抽象类 第1章 继承 1.1 继承的概述 在现实生活中,继承一般指的是子女继承父辈的财产.在程序中,继承描述的是事物之间的所属关系,通过继 ...
- Java类、属性、方法、构造方法、块、内部类的基本概念
类 概念:类相当于一个模板,里面定义了多个对象共同的属性和方法 基本结构:属性.方法.构造方法.块.内部类 声明形式:[访问权限修饰符][修饰符] class 类名 { 类体 } 属性 概念:存放对象 ...
- NoSQL数据库的分布式算法
本文译自 Distributed Algorithms in NoSQL Databases 系统的可扩展性是推动NoSQL运动发展的的主要理由,包含了分布式系统协调,故障转移,资源管理和许多其他特性 ...
- Trie树的数组实现原理
Trie(Retrieval Tree)又称前缀树,可以用来保存多个字符串,并且非常便于查找.在trie中查找一个字符串的时间只取决于组成该串的字符数,与树的节点数无关.因此,它的查找速度通常比二叉搜 ...