Vue2.5 旅游项目实例10 城市选择页-路由配置
创建分支:city-router
拉取到本地并切换分支:
git pullgit 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"></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"></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 mastergit merge city-router
git push
以上是 Vue2.5 旅游项目实例10 城市选择页-路由配置 的全部内容, 来源链接: utcz.com/z/377995.html