vue关闭当前路由页面并跳转到其父页面

1.dom中添加关闭或取消按钮

   <el-button type="primary" class="blueLinearbg cancelBtn" @click="cancel" >取 消</el-button>

2.cancel方法中

  /*取消或关闭*/
        cancel(){
          this.$store.dispatch("tagsView/delView", this.$route);  //关闭当前路由
          this.$router.push({ path: "/wzx/jcjhua/jyjl"});  //跳转至它父页面,路径为地址栏localhost后的路径
        }

在这里插入图片描述

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3中,你可以使用Vue Router来进行页面跳转,包括跳转到子路由页面。以下是一种常见的实现方式: 首先,确保你已经安装了Vue Router,并将其配置到你的Vue应用中。 接下来,在你的路由配置文件(通常是`router/index.js`)中,定义你的路由和子路由: ```javascript import { createRouter, createWebHistory } from 'vue-router'; const routes = [ { path: '/', name: 'Home', component: Home }, { path: '/parent', name: 'Parent', component: Parent, children: [ { path: 'child', name: 'Child', component: Child } ] } ]; const router = createRouter({ history: createWebHistory(), routes }); export default router; ``` 在上面的例子中,我们定义了一个父级路由`/parent`,并在它下面定义了一个子路由`/parent/child`。 在你的父级组件中(例如`Parent.vue`),你可以使用`<router-link>`标签来创建一个链接到子路由的导航链接: ```html <template> <div> <h1>Parent Component</h1> <router-link :to="{ name: 'Child' }">Go to Child</router-link> <router-view></router-view> </div> </template> ``` 上述代码中,我们使用`<router-link>`将文本"Go to Child"包裹起来,并设置了`to`属性为`{ name: 'Child' }`,这将链接到我们在路由中定义的子路由。 最后,在你的子组件中(例如`Child.vue`),你可以按照需要进行渲染: ```html <template> <div> <h2>Child Component</h2> <!-- 子组件内容 --> </div> </template> ``` 这样,当用户点击父组件中的导航链接时,Vue Router将会自动加载并渲染子组件。 请确保你根据自己的项目结构和需求进行适当的调整。希望这个示例能帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值