Vue中路由的嵌套
import Vue from 'vue';
import App from './App.vue'; //引入公共的scss 注意:创建项目的时候必须用scss import './assets/css/basic.scss'; /*路由的嵌套 1.配置路由
{ path: '/user', component: User,
children:[
{ path: 'useradd', component: UserAdd }, { path: 'userlist', component: Userlist } ] } 2.父路由里面配置子路由显示的地方 <router-view></router-view>
*/ //请求数据 import VueResource from 'vue-resource';
Vue.use(VueResource); import VueRouter from 'vue-router'; Vue.use(VueRouter); //1.创建组件 import Home from './components/Home.vue'; import News from './components/News.vue'; import Content from './components/Content.vue'; import User from './components/User.vue'; import UserAdd from './components/User/UserAdd.vue';
import Userlist from './components/User/Userlist.vue'; //2.配置路由 注意:名字 const routes = [
{ path: '/home', component: Home },
{ path: '/news', component: News,name:'news' }, { path: '/user', component: User,
children:[
{ path: 'useradd', component: UserAdd }, { path: 'userlist', component: Userlist } ] }, { path: '/content/:aid', component: Content }, /*动态路由*/ { path: '*', redirect: '/home' } /*默认跳转路由*/
] //3.实例化VueRouter 注意:名字 const router = new VueRouter({
mode: 'history', /*hash模式改为history*/
routes // (缩写)相当于 routes: routes
}) //4、挂载路由 new Vue({
el: '#app',
router,
render: h => h(App)
}) //5 <router-view></router-view> 放在 App.vue
<template>
<div id="app">
<header class="header">
<router-link to="/home">首页</router-link>
<router-link to="/news">新闻</router-link>
<router-link to="/user/useradd">用户</router-link>
</header>
<hr>
<router-view></router-view>
</div>
</template>
<script>
export default {
data () {
return {
msg:'你好vue'
}
}
}
</script>
<style lang="scss">
.header{
height:4.4rem;
background:#000;
color:#fff;
line-height:4.4rem;
text-align:center;
a{
color:#fff;
padding:0 2rem
}
}
</style>
<template>
<!-- 所有的内容要被根节点包含起来 -->
<div id="user"> <div class="user"> <div class="left">
<ul>
<li>
<router-link to="/user/useradd"> 增加用户</router-link>
</li> <li>
<router-link to="/user/userlist"> 用户列表</router-link>
</li>
</ul> </div> <div class="right"> <router-view></router-view> </div> </div> </div>
</template> <script>
export default{
data(){
return {
msg:'我是一个user组件' }
}
} </script> <style lang="scss" scoped> .user{ display:flex; .left{ width:200px; min-height:400px; border-right:1px solid #eee; li{ line-height:2;
}
} .right{
flex:1;
} }
</style>
<template>
<div id="adduser">
增加用户
</div>
</template>
Vue中路由的嵌套的更多相关文章
- Vue中路由的使用
在Vue中动态挂载组件 首先需要安装 cnpm install vue-router --save 在main.js中引入VueRouter 并使用 定义一个路由 创建router实例 通过rout ...
- vue中路由按需加载的几种方式
使用vue-cli构建项目后,我们会在Router文件夹下面的index.js里面引入相关的路由组件,如: import Hello from '@/components/Hello' import ...
- vue中路由返回上一个页面,恢复到上一个页面的滚动位置
第一步:路由文件的配置(对你所需要的vue文件进行保存缓存标志的添加) import Vue from 'vue' import Router from 'vue-router' import Hel ...
- vue中路由
关于每次点击链接都要刷新页面的问题众所周知,开发单页应用就是因为那丝般顺滑的体验效果,如果每次点击都会刷新页面… 出现这个的原因是因为使用了window.location来跳转,只需要使用使用rout ...
- vue中路由传值url--路径传值
在vue项目中我们使用路径的方式一般有一下两种方式this.$route.params.userId;一种需要在router上配置对应的数据key, this.$route.query.userId;
- vue中路由拦截无限循环的情况
router.beforeEach(async (to, from, next) => { if (token) { if (whiteList.indexOf(to.path) != -1) ...
- vue中路由传参的方式
一.params的类型: 配置路由格式: /router/:id 传递的方式: 在path后面跟上对应的值 传递后形成的路径: /router/123, /router/abc 通过:to字符串拼接的 ...
- vue中路由懒加载实现amd加载文件
一般我们配置路由的时候是import引入: import log from '@/components/login': { path: '/login', component: log , hidde ...
- vue中路由跳转的底层原理
前端路由是直接找到与地址匹配的一个组件或对象并将其渲染出来.改变浏览器地址而不向服务器发出请求有两种方式: 1. 在地址中加入#以欺骗浏览器,地址的改变是由于正在进行页内导航 2. 使用H5的wind ...
随机推荐
- 乔布斯在位时,库克实质上已经在做CEO的工作了:3星|《蒂姆·库克传》
“ 一些人认为艾夫是接替乔布斯的热门人选,他对苹果的原晃和产品来说至关重要,但他本人对管理企业却毫无兴趣.艾夫想继统做设计.在苹果,他拥有所有设计师都梦寐以求的工作环境——无限的资源和自由创作的空间. ...
- 神经网络学习中的损失函数及mini-batch学习
# 损失函数(loss function).这个损失函数可以使用任意函数,# 但一般用均方误差(mean squared error)和交叉熵误差(cross entropy error)等一切都在代 ...
- 项目前端 - vue配置 | axios配置 | cookies配置 | element-ui配置 | bootstrap配置
vue项目创建 环境 1.傻瓜式安装node: 官网下载:https://nodejs.org/zh-cn/ 2.安装cnpm: >: npm install -g cnpm --regis ...
- 堆优化Prim 最小生成树 模板
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; const int MAXM = 200005; ...
- kth-largest-element
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- 2019红帽杯部分wp
xx 程序首先取输入的前4个字符作为xxtea加密的密钥之后进行xxtea加密.接着进行位置置换操作,然后又进行了以3个为一组的异或 首先逆向解出xxtea加密之后的结果 #include<st ...
- [React] Create an Animate Content Placeholder for Loading State in React
We will create animated Content Placeholder as React component just like Facebook has when you load ...
- Hive ACID和事务表支持详解
一.ACID介绍 ACID就是常见数据库事务的四大特性:Atomicity(原子性).Consistency(一致性).Isolation(隔离性).Durability(持久性). 在Hive 0. ...
- DOS窗口操作MySQL数据库
本周学习内容: 1.学习MySQL数据库.Linux私房菜: 2.等级评测培训: 3.练习MySQL数据库.练习CentOS7: 实验内容: 1.使用DOS窗口进入MySQL数据库 2.解决MySQL ...
- Linux学习建议[转]
端正学习态度学linux不会为了当黑客或者骇客,如果你为了当黑客或骇客而学习Linux,那么你离进监狱不远了,只是时间早晚而已.很多小白都知道“黑客攻击工具”很多来源与Linux平台上的,我也曾指导过 ...