【vue】this.$router.replace跳转不起作用 Router push or replace not working

项目场景:

商城APP底部导航切换对应页面


问题描述

提示:这里描述项目中遇到的问题:

Just sit there clicking the home btn watching log show me /home but never getting there…

export default {
    name: 'TabBarItem',
    props: {
      path: String
    },
 }
 methods: {
      itemClick () {
        this.$router.push(this.path)
        console.log(this.path);
      }
    },

debug过程:

google,
first key search words are this. r o u t e r 切 换 导 航 失 败 , 出 现 相 关 博 客 , t h i s . router切换导航失败,出现相关博客,this. routerthis.router.push路由不跳转
second key search words are this.$router.push not working 搜索框出现相关词nuxt,点击推荐链接搜索,出现一个vue博客,看了2遍,博主说到自己debbug的方法,在搜索框输入路径,准确的,遂效仿之,发现我自己的页面没有跳转出对应页面,检查代码,终于找到漏了import

总结 debug方法
1.排除是否是点击有问题 检查itemClick,在itemClick方法里打log
2.排除是否是path没有传过来,在itemClick方法里打log(this.path)
3.在搜索框里直接输入检查route是否成功(***)


解决方案:

component代码添加import

{
    path: '/category',
    component: () => import('../views/category/category.vue')
  }, {
    path: '/cart',
    component: () => import('../views/cart/cart.vue')
  }, {
    path: '/profile',
    component: () => import('../views/profile/profile.vue')
  }
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值