vue中...对象解构多层结构

//number one
const user = {
    id:1,
    name:'xiaoming',
    age: 20,
    sex: '女',
    edcation:{
        degree:'Master'
    }
}
const { edcation:{ degree } } = user
console.log(degree) // prints: Master

//number two 1.取别名 2.设置默认值
const user = {
    id:1,
    name:'maiming',
    age: 20,
    sex: '女',
    // hobby: 'Swimming',
    education:{
        degree:'Master',
        user: {
            userId: 2,
            userName:'maiming-1',
        }
    }
}
const { sex: gender, hobby = 'running', education:{ user: {userId: id, userName} } } = user
console.log(gender,hobby, id, userName) // 女 running 2 maiming-1

你可能感兴趣的:(vue中...对象解构多层结构)