A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

vue编程式导航,意思就是用js来跳转页面,项目中用到最多的就是当点击某个按钮时判断当前登录没登录,没有登录点击的时候跳转到登录页面。例子:
<template>
<button @click="getNews()">通过js跳转</button>
</template>
<script>
export default{
data(){
return{
}
},
methods:{
getNews(){
this.$router.push({path:'./login'})//这种是通过path
this.$router.push({path:'./login/1'})//这种是动态路由
this.$router.push({name:'login',params:{id:1}})//这种是命名路由,路由配置时候的name,还可以传参数
}
}
}
</script>
this.$router.go()用来作为 后退/前进导航
  this.$router.go(1);
  this.$router.go(-1);
路由选择(模式)
new VueRouter({
mode:'history'//会有问题,需要后台一起进行配置,默认是哈希模式带“#”的这种
})



---------------------本文来自 weixin_42554311 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/weixin_425 ... 001?utm_source=copy

1 个回复

倒序浏览
奈斯
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马