In vue, select a piece of data from the list to modify the pop-up window, how to achieve the most elegant?

topic description

For the data in the

list, select one, click modify, and the pop-up window displays the details. You can modify it. Click OK to forward the data, and click cancel to close the pop-up window

.
Mar.29,2021

what I'm doing now is to pass the variable to the pop-up component when a row is selected for editing.

I use JSON.parse (JSON.stringify (xxx) to make a deep copy when I mounted in the pop-up widget. Although this is a problem for unusual objects, such as Date,File, generally speaking, the edited data does not contain this type. In this way, compared with Object.assign, if the data contains arrays or nested objects, there will be no reference problems and mistakenly modify the original data.

the pop-up window component only modifies its own deeply copied values, commit and close are events passed to the parent, and the actual submitted data and the actual action of closing the pop-up window are handed over to the parent component.

in this way, the function of the component is relatively simple and convenient for modularization.


HM? Is it that complicated? There is no need to record the value of each change in the time control, you just need to get the dateProp when the user clicks the "OK" button. The realization of the whole function is actually less troublesome:
1. The user clicks "modify", showEditContainer (rowValue) to pass in all the values of this row
2. In the body of the showEditContainer method, first format the rowValue to the format you want (such as the time format you said you want to change), and then fill in the corresponding editing items.
3. The user edits the item you want to change, click the "OK" button, and you get the current value of all items (it is assumed that all the item users have changed it is relatively simple), then encapsulate it into the format that the backend wants, and send the request to the backend.
4. Close the edit box.


  1. does the entire project use self-written components or component libraries like Element or Vuetify? If it is a component library, then binding a piece of data can show or hide the pop-up box without v-if (a little more elegant? )
  2. consider using libraries such as lodash for pick, clone, deepClone
  3. the timing of deep copy does not need to be triggered by watch visible. You can make a deep copy when you click the modify button
  4. time processing can be done at save time, and there is no need to trigger
  5. through watch.

all in all, prepare the data when you click "modify", modify the data bound to the pop-up box to display the pop-up box, save the data when you click save, and hide the pop-up box
as to whether the prepared data should be destroyed after saving the data or canceling the modification, you don't have to destroy it.


you said you wanted to use computed, but you didn't see it in your code.
besides, is watch necessary?

you pop up the data you want in the window and click on the event to modify it.

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-1b3ad06-2c250.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-1b3ad06-2c250.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?