<template>
<div>

测试5

</div>
</template>

<script>
export default {
name: 'Test5',
components: {},
data() {

return {

}

},
computed: {},
created() {},
mounted() {},
methods: {


arrAddAttribute() {
  const arr = [
    { name: 'kkw', age: 23 },
    { name: 'qqq', age: 24 },
    { name: 'www', age: 25 }
  ]
  const target = []
  arr.forEach((item,index)=> {
    target.push(Object.assign({},item,{newAttribute: 'xxxx', newAttribute2: 'yyyy'}))
  })
  console.log(target)
}
/*
* Object.assign用于对对象的合并
*   第一个参数,目标对象
*   第二个参数到后面所有的参数, 源对象,就是你需要组合的对象
* forEach可以用map啥的代替,只要可以循环遍历数组的每一项就行
* */

}
}
</script>

<style scoped lang="scss">

</style>


kkw凯凯王
42 声望2 粉丝