• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Vue this.$router.push(参数)实现页面跳转操作

vue 搞代码 4年前 (2022-01-08) 31次浏览 已收录 0个评论

这篇文章主要介绍了Vue this.$router.push(参数)实现页面跳转操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

很多情况下,我们在执行点击按钮跳转页面之前还会执行一系列方法,这时可以使用 this.$router.push(location) 来修改 url,完成跳转。

push 后面可以是对象,也可以是字符串:

 // 字符串 this.$route<span style="color:transparent">本文来源gaodai#ma#com搞*!代#%^码$网!</span>r.push('/home/first') // 对象 this.$router.push({ path: '/home/first' }) // 命名的路由 this.$router.push({ name: 'home', params: { userId: wise }})

跳转页面并传递参数的方法:

1.Params

由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效。需要用name来指定页面。

及通过路由配置的name属性访问

在路由配置文件中定义参数:

 /* router.js 文件*/ import Vue from "vue"; import Router from "vue-router"; import MediaSecond from "@/views/EnterprisePage/MediaMatrix/second"; //资讯列表 Vue.use(Router); export default new Router({ routes: [ /* 进行路由配置 */ { name: "MediaSecond", path: "/MediaSecond", component: MediaSecond }, ] }) /* 后面还需要接一空行,否则无法通过 ESlint 语法验证 */

通过name获取页面,传递params:

this.$router.push({ name: ‘MediaSecond’,params:{artistName:artistName,imgUrl:imgUrl,type:2} })

在目标页面通过this.$route.params获取参数:

 if (this.$route.params.type == 2) { this.type = apis.getAtistDetails; } else { this.type = apis.getMessageList; }

2.Query

页面通过path/name和query传递参数,该实例中row为某行表格数据

this.$router.push({ name: ‘DetailManagement’, query: { auditID: row.id, type: ‘2’ } });

this.$router.push({ path: ‘/DetailManagement’, query: { auditID: row.id, type: ‘2’ } });

在目标页面通过this.$route.query获取参数:

this.$route.query.type

补充知识:vue this.$router.push(‘./map’);无法跳转的问题

  <div style="text-align: center"> 登录</div> 

router中是这样引入的

import map from ‘@components/map’

点击事件无法跳转

2.解决方法:

改变引入方式

import map=r=>require.ensure([],()=>(require(‘../components/map’)),’map’)

这样通过静态引入就没问题了!

以上就是Vue this.$router.push(参数)实现页面跳转操作的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Vue this.$router.push(参数)实现页面跳转操作

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址