Does Vue.js have a built in way to add a copy of a persistent object to a repeated array

后端 未结 4 1431
逝去的感伤
逝去的感伤 2020-12-03 07:28

I have a Vue.js app where I have a v-repeat on an array of items. I want to add a newItem to the list of items. When I try this.items.push(this.newItem) the obj

4条回答
  •  一向
    一向 (楼主)
    2020-12-03 07:44

    The top answer is wrong. Vue.util.extend has nothing to do with jQuery's extend. It's always a shallow clone. https://github.com/vuejs/vue/issues/1849#issuecomment-158770874

    Object.assign and Spread operator are also shallow copy. see this https://scotch.io/bar-talk/copying-objects-in-javascript

    Simply use the implementation of Ramda.js https://github.com/ramda/ramda/blob/v0.26.1/source/internal/_clone.js

    _curry is not necessary if you don't want them.

    Or check this MVA What is the most efficient way to deep clone an object in JavaScript?

提交回复
热议问题