let {
path,
component,
} = router;
这种语法,到底是个啥意思,我试了半天,没懂,求解。
这段代码的意思是,将router这个对象中的path,component属性拿出来赋给同名的自定义变量path 和component. 也叫解构赋值。
解构赋值 一般解构的值不会拿来修改都是拿来使用的,所以会用const声明为常量
等号右边一般是个对象,左边花括号里面声明的是右边对象属性的映射
const router = {
path: "111",
component: "222",
};
const { path, component } = router;
console.log(path, router.path);//111 111
console.log(component, router.component);//222 222
看看阮一峰的es6书https://es6.ruanyifeng.com/