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 ...
随机推荐
- 17-matlab例题练习
练习 %编写程序使任意输入的一个数反转,如输入123456,输出654321 clc,clear; a = input('输入一个整数\n'); b = 0; while a ~= 0 b = b ...
- Web框架Danjgo之session cookie及认证组件
一 Cookie 1 什么是Cookie Cookie翻译成中文是小饼干的意思.其实Cookie是key-value结构,类似于一个Python中的字典.随着服务器端的响应发送给客户端浏览器. 然后客 ...
- xslt中substring 函数的用法
1.函数定义: string substring(string, number, number?) 2.xslt中substring 函数功能: 返回第一个参数中从第二个参数指定的位置开始.第三个参数 ...
- overflow visibility opacity(透明度) vertical-align 等等
一,overflow属性: 1,四个值: visible 默认值.内容不会被修剪,会呈现在元素框之外. hidden 内容会被修剪,并且其余内容是不可见的. ...
- URLEncoder.encode转译后“空格”变“加号”的问题的解决方案
我用dst_fname=URLEncoder.encode(dst_fname);对字符串dst_fname进行编码,但是发现空格全部都变成了加号,我们提需求的傻B非得要空格的,但是不编码有很多非常特 ...
- PAT 甲级 1005 Spell It Right (20)(代码)
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- 自己动手开启QUIC(转载)
源:https://www.bennythink.com/quic.html#title-0 今天在推上偶然发现 Google 在自己的服务器上启用了 QUIC,QUIC 这东西嘛(发音同 quick ...
- Android.Tools.Summary
Android平台上工具的总结 每个工具的详细使用和深入理解参考每个工具相关的blog. 1. Android SDK中提供的工具 http://developer.android.com/tools ...
- 神啊!PS是你这样用的吗?
对于古典油画名作,人们总是持欣赏的态度去观看.能流传至今的作品,也都是当时的名作. 不过,乌克兰艺术家 Alexey Kondakov 却不是这样的,在他手中,那些世界名画也不过是他恶搞的素材罢了. ...
- CURLOPT_HEADER
curl_setopt($curl, CURLOPT_HEADER, false); true:输出请求头