采用以下代码行
const [component] = router.getMatchedComponents({ ...to })
谁能建议组件周围的方括号在这里是什么意思?我试图用谷歌搜索这个,但很难找到答案
它
被称为解构赋值,它用于解压缩array
的值并将它们分配给新变量。
所以在你的代码中:
const [component] = router.getMatchedComponents({ ...to })
您将router.getMatchedComponents({...to})
返回的array
中保存的第一个元素分配给 component
变量,其中 to
是一个类似数组的结构,使用 spread 操作转换为object
。