vue怎样实现从A页面跳转到B页面

发布时间:2021-09-13 07:32:50 作者:chen
来源:亿速云 阅读:181

本篇内容介绍了“vue怎样实现从A页面跳转到B页面”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

本文操作环境:windows7系统、Vue2.9.6版,DELL G3电脑。

vue怎么实现A页面跳转到B页面?

vue 从A界面跳转到B界面并携带参数

最近遇到一个需求,需要从A界面点击一个按钮跳转到B界面,并且携带参数。

我是这样子实现了需求:

A页面:

<el-button size="mini"
                   type="success"
                   @click="add"
                   icon="el-icon-plus"
                   round
                   plain>{{$t('common.add')}}</el-button>
        <el-button type="primary"
                   size="mini"
                   @click="edit"
                   icon="el-icon-edit"
                   plain
                   round>{{ $t('common.edit') }}</el-button>

点击事件:

add() {
      this.lockTaskStatus = 'new'
      this.toLockTaskManagePage()},edit() {
      this.lockTaskStatus = 'edit'
      this.toLockTaskManagePage()},toLockTaskManagePage() {
      this.$router.push({
        path: '/taskLockManage',
        name: 'TaskLockManage',
        params: {
          status: this.lockTaskStatus        }
      })}

将将跳转的url添加到 $router中。

path 中的url 最前面加 / 代表是根目录下,不加则表示是子路由。

通过path + params的组合传递参数。

B页面:

created() {
    this.getParams()
  },
  watch: {
    // 监测路由变化,只要变化了就调用获取路由参数方法将数据存储本组件即可
    $route: 'getParams'
  },
  methods: {
    getParams() {
      // 取到路由带过来的参数
      const res = this.$route.params.status
      console.log('getParams', res)
    }}

最后,还需在router/index.js中注册:

{
    path: '/taskLockManage',
    component: Layout,
    redirect: '/taskManage/index',
    hidden: true,
    children: [
      {
        path: 'taskLockManage',
        component: () => import('@/views/taskManage/taskLockManage'),
        name: 'TaskLockManage',
        meta: { title: 'taskLockManage', icon: 'user', noCache: true }
      }
    ]}

这样,便可实现了跳转。(PS:这是目前发现的比较好的方法,希望哪位大佬有更好的方法指导。)

“vue怎样实现从A页面跳转到B页面”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. HAproxy实现从入门到进阶
  2. 怎么阻止php页面跳转

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue

上一篇:vue怎么实现页面跳转

下一篇:如何离线安装vue脚手架

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》