resolveMode
A function that determines whether the form should operate in create mode or edit mode. When the form component mounts, <VueForm> calls resolveMode with the context. Within context, you can find itemId prop and it's value which can be useful to identify the mode.
js
{
resolveMode: (context) => {
const { itemId } = context;
return itemId == "+" ? "CREATE" : "UPDATE";
};
}- Returns
CREATE: Form enters create mode. No API call is made; default field values are used. - Returns
UPDATE: Form enters edit mode. Thereadfunction is called withitemIdto fetch existing data.
Most applications use the same component for both creating and editing records. The URL pattern typically looks like:
https://localhost:7777/users/+ // Create mode
https://localhost:7777/users/7 // Edit mode (ID: 7)Based on the params received from URL here, "+" means a new user needs to be created. A unique ID means we need to open this form in edit mode and hence call read function with the "7" as argument.