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

后端 未结 5 511
你的背包
你的背包 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 10:13

    this is because in javascript objects are copied-by-reference which means though you are changing postData which actually is referencing to original address that holds the data i.e. rows. you can do this

    postData = JSON.parse(JSON.stringify(rows))
    

提交回复
热议问题