什么是<router

编程入门 行业动态 更新时间:2024-10-25 14:24:23
本文介绍了什么是<router-view :key="$route.fullPath">?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是 Vue.js 的新手,我想我对路由器如何处理以下事情有一些了解:

I'm completely new to Vue.js and I think I have a bit of understanding of how a router works with things like:

<router-link to="/">

但我并不真正理解以下行的作用:

But I am not really understanding what the following line does:

<router-view :key="$route.fullPath"></router-view>

我相信路由器视图本身可以确保显示内容,但关键部分是什么意思?

I believe router-view by itself makes sure the content is displayed but what does the key part mean?

推荐答案

参见 特殊属性 - 键

它还可以用于强制替换元素/组件而不是重用它.这在您需要时很有用:

It can also be used to force replacement of an element/component instead of reusing it. This can be useful when you want to:

  • 正确触发组件的生命周期钩子
  • 触发转换

$route.fullPath 已定义作为

完整解析的 URL,包括查询和哈希.

The full resolved URL including query and hash.

如果您将 key 绑定到 $route.fullPath,它将始终 强制替换" 元素/组件.

If you bind key to $route.fullPath, it will always "force a replacement" of the <router-view> element / component every time a navigation event occurs.

如上所述,这很可能是为了触发过渡/动画.

As mentioned above, this is most probably done in order to trigger a transition / animation.

更多推荐

什么是&lt;router

本文发布于:2023-08-03 08:05:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285480.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:amp   lt   router

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!