vue-router踩过的坑1

2021-02-02  本文已影响0人  October_CanYang

项目场景:

<font color=#999AAA >简述项目相关背景:
bug场景:
    在学习vue-router,路由传参的部分的时候,在APP.vue页面中的
</font>

<router-link :to="{name:'Hi1',parmas:{username:'canyang'}}">

在Hi.vue页面中接收参数

<h2>
    {{$route.parmas.username}}
</h2>

<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

问题描述:

<font color=#999AAA >提示:这里描述项目中遇到的问题:
   Error in render:
<font color=red size=5>
报错:
"[Vue warn]: Error in render: "TypeError: Cannot read property 'username' of undefined"</font>
<font color=red size=5>
"TypeError: Cannot read property 'username' of undefined"

</font> 在这里插入图片描述

App.vue错误代码标识

在这里插入图片描述

</font>

<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

Hi.vue文件中错误代码标识

在这里插入图片描述

<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

原因分析:

<font color=#999AAA >问题的分析:
    在报这个错之后,进行了代码查询,router/index.js中name是否一致
    然后检查各个字段,[$route]等参数是否写错
</font>

<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

解决方案:

<font color=#999AAA >具体解决方案:
    对比到params的时候发现单词写错了,所以 改掉就可以了</font>

上一篇 下一篇

猜你喜欢

热点阅读