The problem of using for in to clear the attributes of objects in vue

use vue+element to do a simple function, that is, a table is to click the add button, enter a piece of data, and then add the input data to a column of the table. As a result, there is a problem. Go directly to the code:

.
 handleAdd() {
      this.dialogFormVisible=false
      console.log(this.form)
      this.tableData.unshift(this.form)
      for(let key in this.form){
        this.form[key]=""
      }
    },
formv-modelformtableDatafor informtableDatajsformtableData

Feb.11,2022

the one who commented has already explained the point

this.tableData.unshift (this.form);

this step requires copying the this.form


Why is it empty? if you break the point, you can see that the form data was assigned before your for in.
because you assign a pointer to form, which points to the place where form data is stored in memory. When you execute for in, form is emptied, which is equivalent to emptying form data in memory. Because the form data referenced in tableData points to the same memory location, it will also reference empty data.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b6ee-2c286.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b6ee-2c286.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?