Vue中路由的跳转方式

一、<router-link to=''></router-link>

Header.vue

 <template>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a href="" class="navbar-brand">Pizz点餐系统</a>
<ul class="navbar-nav">
<li><router-link to="/admin" class="nav-link">管理</router-link></li>
<li><router-link to="/about" class="nav-link">关于我们</router-link></li>
</ul>
</nav>
</header>
</template>

router.js

 import Vue from 'vue'
import Router from 'vue-router' Vue.use(Router) export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/admin',
12 component: () => import('./components/Admin.vue')
},
{
path: '/about',
16    component: () => import('./components/about/About.vue'),
},
{
path:'*',
redirect:'/'
}
]
})

main.js

 import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store' Vue.config.productionTip = false new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')

在下面的方法中main.js就不重复写了

二、<router-link :to=''></router-link>,绑定数据的方式

Header.vue

 <template>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a href="" class="navbar-brand">Pizz点餐系统</a>
<ul class="navbar-nav">
<li><router-link :to="homeLink" class="nav-link">主页</router-link></li>
</ul>
</nav>
</header>
</template>
<script>
export default{
data(){
return {
homeLink:'/'
}
}
}
</script>

router.js

 import Vue from 'vue'
import Router from 'vue-router' Vue.use(Router) export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: () => import('./components/Home.vue')
},
{
path:'*',
redirect:'/'
}
]
})

三、路由中定义name的方法

Header.vue

 <template>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a href="" class="navbar-brand">Pizz点餐系统</a>
<ul class="navbar-nav">
<li><router-link :to="{name:'menu'}" class="nav-link">菜单</router-link></li>
</ul>
</nav>
</header>
</template>

router.js

 import Vue from 'vue'
import Router from 'vue-router' Vue.use(Router) export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/menu',
name: 'menu',
component: () => import('./components/Menu.vue')
},
{
path:'*',
redirect:'/'
}
]
})

Vue路由的跳转方式的更多相关文章

  1. vue路由的跳转-路由传参-cookies插件-axios插件-跨域问题-element-ui插件

    ---恢复内容开始--- 项目初始化 创建一个纯净的vue环境项目,手动书写全局的样式配置,全局的main,js配置 (1)如果vue项目在重构或者出错的时候,手动安装node_modules. 如果 ...

  2. vue 路由 及 跳转传递参数的总结

    博客地址:https://ainyi.com/4 vue-router vue-router 是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用.vue的单页面应用是基 ...

  3. vue路由懒加载方式

    方式一:结合Vue的异步组件和Webpack的代码分析 const Home = resole => {require.ensure(['../components/Home.vue'],() ...

  4. vue路由跳转的方式

    vue路由跳转有四种方式 1. router-link 2. this.$router.push() (函数里面调用) 3. this.$router.replace() (用法同push) 4. t ...

  5. 详解vue 路由跳转四种方式 (带参数)

    详解vue 路由跳转四种方式 (带参数):https://www.jb51.net/article/160401.htm 1.  router-link ? 1 2 3 4 5 6 7 8 9 10 ...

  6. 2种方式解决vue路由跳转未匹配相应路由避免出现空白页面或者指定404页面

    https://www.cnblogs.com/goloving/p/9254084.html https://www.cnblogs.com/goloving/p/9254084.html 1.路由 ...

  7. vue路由跳转的多种方式

    1.router-link to 跳转 <router-link to="/child"><button>跳转</button></rou ...

  8. Vue路由守卫(跳转页面置顶的处理方)

    在用Vue 框架开发时,在电脑调试没有任何问题,但是用手机调试时会发现页面跳转的不对.就是跳转时页面展示的滑动位置不对,会保留上次跳转页面时的跳转位置.因此需要对页面的路由跳转进行优化,需要用到Vue ...

  9. Vue路由传参的几种方式

    原 Vue路由传参的几种方式 2018年07月28日 23:52:40 广积粮缓称王 阅读数 12613   前言:顾名思义,vue路由传参是指嵌套路由时父路由向子路由传递参数,否则操作无效.传参方式 ...

随机推荐

  1. Missing artifact com.sun.jmx:jmxri:jar:1.2.1的解决方法

    maven项目添加log4j-1.2.15依赖出现Missing artifact com.sun.jmx:jmxri:jar:1.2.1错误 解决方法一:修改log4j.jar的版本为1.2.16或 ...

  2. MariaDB基本命令

    --查看当前日期select current_date();--查看当前时间select current_time();--查看当前日期.时间select now();--查看当前用户select u ...

  3. [Algorithm] Area of polygon

    How to calculate the area of polygon. For a triangle like: We can calculate the area: function cross ...

  4. webuploader如何判断是否上传的是空文件?

    在'beforeFileQueued'事件中可以判断: // 当有文件被添加进队列的时候 uploader.on( 'beforeFileQueued', function( file ) { if( ...

  5. LeetCode---Backtracking && DP

    **322. Coin Change 思路:动态规划,构造一个数组,存入当前index最少需要多少个coin public int coinChange(int[] coins, int amount ...

  6. JS基础_变量提升和函数提升

    1.在函数中,不使用var声明的变量都会变为全局变量 function fun(){ d=10; //window.d=10; }; console.log(10);//10 2.定义形参就相当于在函 ...

  7. Spring Boot学习笔记(1)

    @SpringBootApplication用于注解Spring启动类,如下所示 @SpringBootApplication public class Application { public st ...

  8. mysql使用命令行执行存储过程

    编写存储过程sql 以给brand表添加phone字段为例: DROP PROCEDURE IF EXISTS UpdateColum; CREATE PROCEDURE UpdateColum() ...

  9. Android通过JNI实现守护进程与卸载后跳转指定网页

    JNI进程守护 c代码部分如下:JNIEXPORT void JNICALL Java_com_sharetimes_qude_jni_JNIDaemon_daemon(JNIEnv * env, j ...

  10. TensorFlow 学习(1)——第一个程序:线性回归

    目前这个程序还有很多地方没有搞懂,先跑一跑例程看看效果如何.从结果来看,最终的训练成果能够接近于预设的数据