基于vue-cli的vue项目之路由6--重定向2-----页面初始化重定向
来源:互联网 发布:手机 淘宝联盟登陆不上 编辑:程序博客网 时间:2024/04/29 06:46
既然使用重定向可以让我们路由被选中的时候重定向到另一个页面,那么我们怎么让进来的时候初始化到其中一个路由呢?,
1.hello.vue子界面:用来显示的子界面<template><div class="hello"><h1>这个是hello.vue页面</h1><h2></h2></div></template><script>export default {name: 'hello',}</script>2.router/index.js:路由配置文件,关键在于第二十八到第三十二行import Vue from 'vue'import VueRouter from 'vue-router'Vue.use(VueRouter)const router = new VueRouter({routes: [{path: '/hello',component: require('../components/Hello.vue'),},{path: '/foo',component: require('../components/foo.vue'),},{path:'*',redirect:"/hello"}]})export default router;3.app.vue:主界面<template><div id="app"><!-- <hello></hello> --><div class="nav"><ul><li><router-link to="/hello">hello页面</router-link></li><li><router-link to="/foo">foo页面</router-link></li></ul></div><div class="main"><router-view></router-view></div></div></template><script>export default {name: 'app',components: {},}</script><style>body {background-color: #f8f8ff;font-family: 'Avenir', Helvetica, Arial, sans-serif;color: #2c3e50;}.nav {position: fixed;width: 108px;left: 40px;}.nav ul {list-style: none;margin: 0;padding: 0;}.nav ul li {width: 108px;height: 48px;line-height: 48px;border: 1px solid #dadada;text-align: center;}.nav ul li a {display: block;position: relative;text-decoration: none;}.nav ul li img {position: absolute;left: 0;top: 0;width: 100px;height: 30px;}.main {height: 400px;margin-left: 180px;margin-right: 25px;}</style>main.js:配置路由路径import Vue from 'vue'import App from './App'import VueRouter from 'vue-router'import router from './router'Vue.use(VueRouter);new Vue({el: '#app',router,render: h => h(App)})
效果是这样的:
阅读全文
1 0
- 基于vue-cli的vue项目之路由6--重定向2-----页面初始化重定向
- 基于vue-cli的vue项目之路由6--重定向1-----path无参重定向
- 基于vue-cli的vue项目之路由6--重定向1-----路径无参重定向
- 基于vue-cli的vue项目之路由6--重定向4-----path带参重定向
- 基于vue-cli的vue项目之路由6--重定向3-----method返回重定向路径
- vue-cli 路由重定向
- Vue路由重定向(第一次写博客)
- vue重定向
- 基于vue-cli的vue项目之路由2--param传参
- 基于vue-cli的vue项目之路由3--watch监听路由
- 基于vue-cli的vue项目之路由4--嵌套路由
- Vue路由(vue-router)配置实战——动态路由,重定向,工程非根目录
- vue项目输入无效地址时重定向到指定页面
- 基于vue-cli的vue项目之路由1--最基本的使用
- 基于vue-cli的vue项目之路由5--router.push,go,replace方法
- MVC 路由重定向
- 页面重定向的使用
- 页面重定向的方法
- 入手树莓派3+python小试GPIO输出
- Scikit-learn机器学习库的安装
- 使用jxl包的importSheet方法抛出空指针异常的解决方法
- [日推荐]『奢客奢侈品』奢侈品交易平台
- android proguard.cfg 文件常用配置
- 基于vue-cli的vue项目之路由6--重定向2-----页面初始化重定向
- Http-Post请求特殊符号变空格的问题解决
- java数据类型
- phpstorm 配置 xdebug
- nRF PPI
- 【Unity与23种设计模式】代理模式(Proxy)
- CoAP协议及开源实现
- STM32 IO口模拟串口通讯
- 使用DLT算法求解相机参数及相机与物体的位置关系(附加C/C++和Matlab代码)