这里为什么push 整个item的话array1 和2同步。但是只push item里面一些属性就不行?可以只push一些属性的时候也同步吗
<template>
<view>
<view style="color: yellowgreen;" @click="click_a">点击测试a</view>
</view>
</template>
<script>
export default {
data() {
return {
array1: [
{
title: "豆腐",
numList: [
{
client: "猫",
itemNum:3
},
{
client: "狗",
itemNum:13
},
{
client: "大帝",
itemNum:21
}
]
},
{
title: "香肠",
numList: [
{
client: "猫",
itemNum:1
},
{
client: "狗",
itemNum:2
},
{
client: "大帝",
itemNum:3
}
]
},
{
title: "芝士",
numList: [
{
client: "猫",
itemNum:123
},
{
client: "狗",
itemNum:111
},
{
client: "大帝",
itemNum:110
}
]
}
],
array2: []
};
},
methods: {
click_a() {
let item = this.array1[0]
this.array2.push({
//直接push item。array1 array2同步。但是像下面这样就不行
title: this.array1[0].title,
client: this.array1[0].numList[0].client,
itemNum: this.array1[0].numList[0].itemNum
})
console.log("this.array2 is: ", this.array2)
this.array1[0].numList[0].client = "超级猫"
console.log("this.array1[0] is: ", this.array1[0])
console.log("this.array2 is: ", this.array2[0])
}
}
}
</script>
<style lang="scss">
</style>