vuejs入门-子路由(三)

上次说了整页导航,这次我们说页面局部导航
局部导航白话就是:页面局部刷新或是视图局部刷新

1.搭建项目:
vue init webpack tj1
2.按图创建文件:

clipboard.png

3.运行案例,然后看源码自己体会:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tj1</title>
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
</body>
</html>

pages/First.vue:
<template>
<div>
<span>第1个页面</span>
<router-link to="/secod" >内容页</router-link>
</div>
</template>

<script>
export default {
data () {
return {
}
}
}
</script>

<style scoped>
span{
font-weight: normal;
color:red
}
</style>

pages/Second.vue:
<template>
<div>
<span>第2个页面</span>
<router-link to="/" >首页</router-link>
<router-view></router-view>
<router-link to="/secod" >第1个子页面</router-link>
<router-link to="/sec2" >第2个子页面</router-link>
<router-link to="/sec3" >第3个子页面</router-link>
</div>
</template>

<script>
export default {
data () {
return {
}
}
}
</script>

<style scoped>
span{
font-weight: normal;
color:red
}
</style>

pages/sec/Sec1.vue:
<template>
<span>第1个子页面</span>
</template>

<script>
export default {
data () {
return {
}
}
}
</script>

<style scoped>
span{
font-weight: normal;
color:red
}
</style>

pages/sec/Sec2.vue:
<template>
<span>第2个子页面</span>
</template>

<script>
export default {
data () {
return {
}
}
}
</script>

<style scoped>
span{
font-weight: normal;
color:red
}
</style>

pages/sec/Sec3.vue:
<template>
<span>第3个子页面</span>
</template>

<script>
export default {
data () {
return {
}
}
}
</script>

<style scoped>
span{
font-weight: normal;
color:red
}
</style>

main.js:
import Vue from 'vue'
import VueRouter from 'vue-router'
import First from './pages/First'
import Secod from './pages/Secod'

import Sec1 from './pages/sec/Sec1'
import Sec2 from './pages/sec/Sec2'
import Sec3 from './pages/sec/Sec3'

Vue.use(VueRouter)

// 定义路由配置
const routes = [
{path: '/',component: First},
{path: '/secod',
component: Secod,
children: [
{path: '/',component: Sec1},
{path: '/sec2',component: Sec2},
{path: '/sec3',component: Sec3}
],
}
/*
这么写就成了一级页面的跳转了,而不是二级局部跳转
{path: '/Sec1',component: Sec1},
{path: '/Sec2',component: Sec2},
{path: '/Sec3',component: Sec3},
*/
]

// 创建路由实例
const router = new VueRouter({
routes
})

// 创建 Vue 实例
new Vue({
el: '#app',/* 对应index.html的div的id="app" */
data(){
return {
}
},
router
})

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这篇开始我们使用npm库:vue-cli的开发方式的深入开发 这次我们只说一个东西:vue的路由处理以及路由方案:...
    矢风阅读 1,280评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • Vue-router学习指南 日记:本文按照vue-router官网的知识结合例子进行分析和讲解,搭建工具(vue...
    sunny519111阅读 5,305评论 0 6
  • MOM:企业消息系统,即面向消息的中间件,提供了以松散耦合的灵活方式集成应用程序的一种机制。它们提供了基于存储和转...
    lyc365happy阅读 2,299评论 0 0
  • 今天上课学习了时间管理来安排事情,我觉得这是个非常需要好好思考学习的。因为我就觉得自己是个有拖延症的家伙,而且有时...
    FineYoga陈泋文阅读 1,280评论 0 1