vue的cli中自定义router
1.安装router
npm install vue-router
2.为了方便管理在components同级创建router文件夹
3.在文件夹中创建index.js文件,就是router文件
import Vue from 'vue'
import Router from 'vue-router'
import routes from './routes'
Vue.use(Router)
const router = new Router({
routes
})
router.beforeEach((to,from,next)=>{
if(to.matched.some((route)=>route.meta.Auth)){
next({
path:'/login',
query:{
returnURL:to.path
}
})
}else{
next()
} })
export default router
4.在这里是把routes分离开,作为一个模块进行定义,在index.js中引入,这样可以使模块更加的细化
import Artical from '../views/Artical'
import Channel from '../views/Channel'
import Index from '../views/Index'
import Setting from '../views/Setting'
import Base from '../views/setting/Base'
import Password from '../views/setting/Password'
import Avatar from '../views/setting/Avatar'
import Login from '../views/Login'
const routes = [
{
path: '/',
component: Index,
redirect:'/artical/1',
children: [
{
path: 'artical/:id',
component: Artical
},
{
path: 'channel/:id',
component: Channel
},
{
path:'setting',
component:Setting,
meta:{
Auth:true
},
redirect:'/setting/base',
children:[
{
path:'base',
component:Base
},
{
path:'password',
component:Password
},
{
path:'avatar',
component:Avatar
}
]
} ]
},{
path:'/login',
component:Login
}
]
export default routes
5.其他文件使用的时候,在routes.js中进行定义就可以啦
vue的cli中自定义router的更多相关文章
- vue的cli中引入css文件
在public文件中创建一个文件夹css,放进reset.css 在main.js中引入即可 import '../public/css/reset.css'就可以啦
- vue 在 html 中自定义 tag
v-if,v-for,:key,:style,v-text,@click,:src,:poster,:class,:href
- 【面试题】Vue中的$router 和 $route的区别
Vue中的$router 和 $route的区别 点击视频讲解更加详细 this.$route:当前激活的路由的信息对象.每个对象都是局部的,可以获取当前路由的 path, name, params, ...
- vue cli 中关于vue.config.js中chainWebpack的配置
Vue CLI 的官方文档上写:调整webpack配置最简单的方式就是在vue.config.js中的configureWebpack选项提供一个对象. Vue CLI 内部的 webpack 配置 ...
- vue中自定义组件(插件)
vue中自定义组件(插件) 原创 2017年01月04日 22:46:43 标签: 插件 在vue项目中,可以自定义组件像vue-resource一样使用Vue.use()方法来使用,具体实现方法: ...
- vue中自定义指令vue.direvtive,自定义过滤器vue.filter(),vue过渡transition
自定义指令 默认设置的核心指令( v-model,v-bind,v-for,v-if,v-on等 ),Vue 也允许注册自定义指令.注意,在 Vue2.0 里面,代码复用的主要形式和抽象是组件——然而 ...
- vue中自定义指令
//vue中自定义指令 //使用 Vue.directive(id, [definition]) 定义全局的指令 //参数1:指令的名称.注意,在定义的时候,指令的名称前面,不需要加 v-前缀; 但是 ...
- Vue中自定义指令的使用方法!
除了核心功能默认内置的指令 (v-model 和 v-show),Vue 也允许注册自定义指令.注意,在 Vue2.0 中,代码复用和抽象的主要形式是组件.然而,有的情况下,你仍然需要对普通 DOM ...
- vue cli中的env详解
前言 相信使用过 vueCli 开发项目的小伙伴有点郁闷,正常开发时会有三个接口环境(开发,测试,正式),但是 vueCli 只提供了两种 development,production(不包含 tes ...
随机推荐
- 第五章 Inheritance继承
[继承] Java不支持多重继承 - 每个子类只有一个超类. 不是将成员变量声明为静态,更好的做法是将University实例化为对象,然后使用该对象访问其成员,如下所示: [抽象类] 可以包含或者不 ...
- twitter oa
字符串括号匹配有效性: 要求从直接return改成了返回yes or no.需要添加到list后break,然后每次循环之前,boolean要重新初始化. array index报错是什么鬼?算了,脑 ...
- ScrollView嵌套ListView,禁止ListView的滚动,只让ScrollView可以滚动
自定义ListView,xml布局文件中使用该自定义的ListView public class NoScrollListview extends ListView{ public NoScrollL ...
- SeekBar
<SeekBar android:id=”@+id/seek”android:layout_width=”match_parent”android:layout_height=”wrap_con ...
- PARAMETERS 指令
语法: PARAMETERS <p> [DEFAULT <f>] [LOWER CASE] [OBLIGATORY] [AS CHECKBOX] [RADIOBUTTON ...
- MVC与WebApi中的异常统一处理
1.简单例子 /// <summary> /// 全局页面控制器异常记录 MVC的异常处理 /// </summary> public class CustomErrorAtt ...
- 基于vue的悬浮碰撞窗口(用于打广告的)组件
由于项目需要改写了一个悬浮碰撞弹窗组件 <template> <div class="floatLayer"> <a class="clos ...
- Employee类
package demo; import java.time.LocalDate; public class Employee { private String name; private doubl ...
- (转)android:inputType参数类型说明
android:inputType参数类型说明 android:inputType="none"--输入普通字符 android:inputType="text" ...
- iOS.ARM-Assembly
ARM Assembly for iOS with Xcode 0. Introduction 0.1 arm asm vs. arm64(ARMv8) asm AArch64: 0.2 __arm6 ...