语法 - 变量声明周围的方括号是什么意思



采用以下代码行

const [component] = router.getMatchedComponents({ ...to })

谁能建议组件周围的方括号在这里是什么意思?我试图用谷歌搜索这个,但很难找到答案

被称为解构赋值,它用于解压缩array的值并将它们分配给新变量。

所以在你的代码中:

const [component] = router.getMatchedComponents({ ...to })

您将router.getMatchedComponents({...to})返回的array中保存的第一个元素分配给 component 变量,其中 to 是一个类似数组的结构,使用 spread 操作转换为object

最新更新