二.Vue2.5开发去哪儿网app城市列表页①——城市选择页面路由配置和Header布局

在pages文件夹下新建city文件夹用于存放city组件和其子组件

路由更新,这里注意city的路径是path: '/city',不再是首页的路径

import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/pages/home/Home'
import City from '@/pages/city/City'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/city',
      name: 'City',
      component: City
    }
  ]
})

接下来就是点击北京这个区域的时候会弹出city组件页面,而北京这这个区域在Home组件中,所以我们要在Home组件的Header子组件中添加router-link

    <router-link to="/city">
      <div class="header-right">
        {{this.city}}
        <span class="iconfont arrow-icon">&#xe64a;</span>
      </div>
    </router-link>

但是整个北京区域变成了绿色,因为router-link元素会设置a标签的颜色为绿色

所以我们在header-right样式中添加 color: #fff

然后完成CityHeader组件的代码编写

<template>
  <div class="header">
    <p>城市选择</p>
    <router-link to="/">
      <div class="iconfont header-back">&#xe624;</div>
    </router-link>
  </div>
</template>

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

<style lang="stylus" scoped>
  @import"~styles/varibles.styl"
  .header
    position: relative
    overflow: hidden
    height: .86rem
    text-align: center
    line-height: .86rem
    color: #fff
    background-color: $bgColor
    font-size: .32rem
    .header-back
      position: absolute
      top: 0
      left: 0
      width: .64rem
      font-size: .4rem
      color: #fff
</style>

最后完成搜索组件Search组件

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

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

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .search
    height .72rem
    background-color $bgColor
    padding 0 .1rem
    .search-input
      overflow hidden
      width 100%
      box-sizing border-box
      padding 0 .2rem
      height .62rem
      text-align center
      border-radius .06rem
      color #666
</style>

完成后效果

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风里有诗句哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值