📂前端
🔖vue
2021-06-16 16:02阅读: 2732评论: 0推荐: 0

vue router:解决相同路径不同路由参数跳转同一页面,路由参数不动态刷新的问题

问题描述

       当我们使用同一路径跳转不同页面时,路由参数不会刷新,所以组件中接收不到,比如我的路由定义和路由跳转链接如下:

       当然我们人为不肯直接这样写啦~这里模拟问题写的demo

采用 watch 监听

       1. 在点击跳转的组件中使用 watch 进行检测动态改变路由参数:

watch: {
    // 利用watch方法检测路由变化:进行重新赋值
    $route: function(to, from) {
      if (to.path !== from.path) {
        this.maintype = to.params.maintype // 获取参数 这里的 mainTpe 是我的路由参数
      }
    }
  }

在这样配置完成之后我还出现了警告,如果没有可以忽略继续
       2. 在页面不使用 props 来接收路由参数,而采用data进行定义

data() {
    return {
      mainType: this.$route.params.mainType,  // 这里的mainTpe是我的路由参数
    };
  },

       这种场景可以用在我们需要根据路由参数渲染页面的不同数据,主页面是一样的,比如我有许多的分类管理,那么我们就可以这样抽离成一个主页面和路由,在组件中根据路由参数来去调用接口进行页面数据的赋值。

有不对和疑问欢迎指出☞

本文作者:苏洬

本文链接:https://www.cnblogs.com/Monster-su/p/14889735.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   苏洬  阅读(2732)  评论(0编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
🔑
  1. 1 soap Max Liese
  2. 2 たぶん YOASOBI
  3. 3 MORE K/DA
  4. 4 混沌世界 蓝心羽
  5. 5 rap do zoro Tauz
soap - Max Liese
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

单依纯 - Soap (Live)

作词:Melanie Martinez、Kyle Shearer、Emily Warren

作曲:Melanie Martinez、Kyle Shearer、Emily Warren

原唱:Melanie Martinez

编曲:周禹成

音乐总监:刘卓

Program:尹之扬

混音:佟尚泽@唯伴音乐

音频编辑:石行@唯伴音乐

Think I just remembered something

I think I left the faucet running

Now my words are filling up the tub

Darling you're just soaking in it

But I know you'll get out the minute

You notice all your fingers pruning up

I'm tired of being careful gentle trying to

Keep the water warm

Let me under your skin

Uh-oh there it goes I said too much it

Overflowed

Why do I always spill

I feel it coming out my throat

Guess I better wash my mouth out with soap

God I wish I never spoke

Now I gotta wash my mouth out

I feel it coming out my throat

Guess I better wash my mouth out with soap

God I wish I never spoke

Now I gotta wash my mouth out with soap

Think I just remembered something

I think I left the faucet running

Now my words are filling up the tub

Darling you're just soaking in it

But I know you'll get out the minute

You notice all your fingers pruning up

I'm tired of being careful gentle trying to

Keep the water warm

Let me under your skin

Uh-oh there it goes I said too much it

Overflowed

Why do I always spill

I feel it coming out my throat

Guess I better wash my mouth out with soap

God I wish I never spoke

Now I gotta wash my mouth out with soap

I feel it coming out my throat

Guess I better wash my mouth out with soap

God I wish I never spoke

Now I gotta wash my mouth out with soap

I feel it coming out my throat

Guess I better wash my mouth out with soap

God I wish I never spoke

Now I gotta wash my mouth out with soap

I feel it coming out my throat

Guess I better wash my mouth out with soap

God I wish I never spoke

Now I gotta wash my mouth out with soap