vue - router 起步

官方API:https://router.vuejs.org/zh/guide/#javascript

 

vue-cli for index.js

 

 1 export default new Router({
 2   mode: 'history', //路由模式,取值为history与hash
 3   base: '/', //打包路径,默认为/,可以修改
 4   routes: [
 5   {
 6       path: string, //路径
 7       ccomponent: Component; //页面组件
 8       name: string; // 命名路由-路由名称
 9       components: { [name: string]: Component }; // 命名视图组件
10       redirect: string | Location | Function; // 重定向
11       props: boolean | string | Function; // 路由组件传递参数
12       alias: string | Array<string>; // 路由别名
13       children: Array<RouteConfig>; // 嵌套子路由
14       beforeEnter?: (to: Route, from: Route, next: Function) => void; // 路由单独钩子
15       meta: any; // 自定义标签属性,比如:是否需要登录
16       icon: any; // 图标
17       // 2.6.0+
18       caseSensitive: boolean; // 匹配规则是否大小写敏感?(默认值:false)
19       pathToRegexpOptions: Object; // 编译正则的选项
20   }
21   ]
22 })

 

vue-cli for main.js

 1 // The Vue build version to load with the `import` command
 2 // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
 3 // 引入vue框架
 4 import Vue from 'vue'
 5 // 引入根组件
 6 import App from './App'
 7 // 引入路由配置
 8 import router from './router'
 9 
10 // 关闭生产模式下给出的提示
11 Vue.config.productionTip = false
12 
13 // 定义实例
14 new Vue({
15   el: '#app',
16   router, // 注入框架中
17   components: { App },
18   template: '<App/>'
19 })

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值