object获取的两种方式:
data() {
return {
abj: {
aa: {A: '1'}
}
}
},
created() {
console.log(this.abj.aa) //第一种
console.log(this.abj["aa"]) //第二种
},
Object.keys使用/解构赋值:
return {
footList: [],
abj: {
aa: {A: '12',AA:'22'},
bb: {B: '1'}
},
ABJ:[100,200,300]
}
},
created() {
this.deepCopy()
//Object.keys返回值是数组
console.log(Object.keys(this.abj)) //参数为对象时 返回值是数组,存放的是对象key
//['aa','b']
console.log(Object.keys(this.ABJ)) //参数为数组时 返回值是数组,存放的是数组索引,和用for in遍历数组的顺序一样
//['0','1','2']
for (const BB in this.ABJ){
console.log(BB)
//0
//1
//2
}
//对象解构赋值
let {A} = this.abj.aa
console.log(A) //12
//数组解构赋值
let [B]= this.ABJ
console.log(B) //100
//扩展运算符
console.log(...this.ABJ) //100 200 300 一行输出的哦
},