首页 > 其他 > 详细

Vue2.5 旅游项目实例10 城市选择页-路由配置

时间:2020-03-17 12:14:28      阅读:75      评论:0      收藏:0      [点我收藏+]

创建分支:city-router

拉取到本地并切换分支:

git pull
git checkout city-router

然后配置路由index.js:

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
    }
  ]
})

在pages下新建city文件夹,创建City.vue文件

我们希望的是在首页点击头部的“北京”,跳到City.vue页,修改home下的Header.vue代码:

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

<style lang="stylus" scoped>
.header-right
  color: #fff
</style>

然后继续编辑City.vue页:

<template>
<div>
  <city-header></city-header>
</div>
</template>

<script>
import CityHeader from ./components/Header
export default {
  name: City,
  components: {
    CityHeader
  }
}
</script>

在city文件夹下,新建components文件夹,创建Header.vue文件:

<template>
<div class="header">
  <router-link to="/">
    <div class="header-left"><div class="iconfont back-icon">&#xe624;</div></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 $headerHeight
  line-height $headerHeight
  text-align:center
  color:#fff
  font-size: .32rem
  background: $bgColor
  .back-icon
    position:absolute
    top:0
    left:0
    width: .64rem
    text-align: center
    font-size: .4rem
    color: #fff
</style>

效果图:

技术分享图片

上传代码:

git add .
git commit -m "ciyt-router"
git push

合并代码:

git checkout master
git merge city-router
git push

 

Vue2.5 旅游项目实例10 城市选择页-路由配置

原文:https://www.cnblogs.com/joe235/p/12469277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!