vuejs copying data object and removing property will remove the property from original object as well

后端 未结 5 509
你的背包
你的背包 2021-02-01 09:27

I have a data object in vue that looks like this

rows[
0 {
  title: \"my title\",
  post: \"my post text\",
  public: false,
  info: \"some info\"
},
1 {
 title:         


        
5条回答
  •  鱼传尺愫
    2021-02-01 09:55

    You need to take a copy of your data by cloning it. There are various ways of cloning the data, I would recommend using lodash's function, cloneDeep

    postDataCopy = _.cloneDeep(postData)

    Then you can modify postDataCopy as you like without modifying the original.

提交回复
热议问题