'Verified pitfalls in Vue 3 business pages, each checked against library source or reproduced: keep-alive name matching, table selection cleared when data is replaced, echo hook timing, close/cancel double-binding that depends on the wrapper''s emits, close firing after a successful save, cleared controls emitting different empty values, date picker writing a Date; UI-library specifics (Element Plus verified; antdv-next and Vant mapped) in references. Use when debugging forms, modals, cached tabs, tables with selection, or when reviewing such code.'
Resources
2Install
npx skillscat add zehuichan/zstack/vue-pitfalls Install via the SkillsCat registry.
Pitfalls
Every entry here was verified by reading source or reproducing the failure, and says which. An entry that is still a hypothesis goes in the library reference under "Unverified", not here. Each entry is symptom, cause, fix.
Find the platform and library from package.json (element-plus, antdv-next, ant-design-vue, vant, uni-app, @tarojs/*) and read the matching file in references/. For a library with no file there, read its source before asserting anything, then add the file.
Cache name differs from the route name
- Symptom. A tab that should keep its filters and scroll position starts fresh on every return, and nothing reports an error.
- Cause.
KeepAliveskips a component unlessincludematches its name:!name || !matches(include, name)leaves it uncached. The name isComponent.name || Component.__name. A stringincludeis split on,and compared exactly, so case and slashes count; an array and a regular expression are also accepted. For<script setup>the SFC compiler fills__namefrom the file's base name, so a page with no explicit name is calledindexoraction. Using the open tabs' route names as theincludelist is the application's tab store, not Vue. - Fix.
defineOptions({ name })equals the routename; an explicit name wins over__name. A backend-delivered menu fixes the route name's shape, so read the menu's value rather than guess. Forms seen in one project: PascalCase, a path such as/finance/day, and a localentity/page. - Source. Read in
@vue/runtime-core3.5.30 (KeepAliveImpl,matches,getComponentName) and@vue/compiler-sfc3.5.30 (__namefrom the filename). The route-name forms come from one project's router.
Table selection is cleared when the data array is replaced
- Symptom. Rows the user ticked disappear after a query, a page change, or any refresh that assigns a new array, and the selection-change handler fires with an empty list. Batch buttons that depend on the selection go disabled.
- Cause. In Element Plus the table's
setDatatakes one of three paths. Withreserve-selectionon the selection column it only asserts thatrow-keyis set and leaves the selection alone. Otherwise, if the array is a different object from the last one, it clears the selection and emits the change event. If it is the same array, it removes only the selected rows no longer present. - Fix. Decide the intent. Selection that should not outlive a refresh needs nothing, but a handler must not assume ticked rows survive an
await query(). Selection that must span pages needsreserve-selectionon the selection column androw-keyon the table; withoutrow-keythe table throws[ElTable] prop row-key is required. Expect selected rows from other pages in the selection list then. - Source. Read in
es/components/table/src/store/index.mjs(setData) andstore/watcher.mjs(clearSelection,cleanSelection,assertRowKey), Element Plus 2.14.0. Other libraries: not checked.
Echo on the after-open event
- Symptom. A modal's form is empty or stale on a later open, or the echo runs before the form's ref exists.
- Cause. With content destroyed on close, the after-open event fires on every open, once the content is mounted. A
watchon the visibility flag fires when the flag flips, which is earlier: in Element Plus the dialog renders its body in its own watcher after the flag changes and destroys it again on close. - Fix. Bind the echo to the after-open event (names in Adapters) and enable destroy-on-close.
- Source. Read in
es/components/dialog/src/use-dialog.mjs(2.14.0) and in the project's modal wrapper, which forwards@openedthrough$attrsand sets destroy-on-close. Other libraries: not checked.
Close and cancel bound together run the handler twice — but only when the wrapper does not declare close
- Symptom. A cancel handler runs twice for one close; anything inside it that prompts or calls out happens twice.
- Cause. The wrapper forwards unknown listeners through
$attrs, so whether a parent's@closereaches the inner component depends on one thing: isclosein the wrapper'semits? If it is not, the listener falls through and the wrapper's own close-mapped event fires too, so two listeners reach the handler for one close. - Fix. Read the wrapper's
emitsbefore deciding. The two wrappers in the source project differ:- Modal —
emits: ['cancel', 'confirm'], noclose. The parent's@closefalls through toel-dialog's ownclose, while@cancelis the wrapper's footer event. Binding both to one handler is safe, and 42 of 59 popup files do it. - Drawer —
emits: ['update:modelValue', 'cancel', 'confirm'], and the innerel-drawer's@closecallscancel. Binding both runs the handler twice; 1 of 59 popup files does it.
- Modal —
- Source. Read in the project's Modal and Drawer wrappers, and counted across
src/views: 43 files bindcloseandcancelto the same handler, 42 of them on a modal and 1 on a drawer. An earlier version of this entry claimed the double binding was universally wrong; the count disproved it.
A close handler also runs after a successful confirm
- Symptom. A handler bound to the dialog's close event runs after a save that closed the dialog itself, and does cancel-style work: it resets the form, prompts "discard changes?", or reports a cancellation.
- Cause. In Element Plus the close event is emitted when the leave transition starts (
beforeLeave), whatever started the close: the X, Esc, a footer button, or the component setting its ownmodelValuetofalse. It is not limited to user dismissal. - Fix. Keep a close-bound handler idempotent and free of prompts or requests. Anything that must happen only on a user cancel goes on the cancel button's own handler.
- Source. Read in
es/components/dialog/src/use-dialog.mjs(2.14.0). Other libraries: not checked.
A cleared control reports an empty value, and which one depends on the control
- Symptom. A filter that defaults to
nullends up asundefinedor''after the user clears it, so=== nullchecks and "is this filled in" logic disagree. Two filters on the same page can disagree with each other. - Cause. A clearable control calls back with its own empty value, and the controls in one library do not agree. In Element Plus 2.14.0 a cleared
el-inputwrites'', a singleel-selectwritesundefined([]when multiple), and a cleared date or time picker and anel-input-numberwritenull.value-on-clear, a global config, or a wrapper can change each of these. - Fix. Treat
'',undefined, andnullas empty: test for emptiness, do not compare tonull. If the request layer filters empty values before sending, a cleared field does not reach the backend as a value; confirm that it does before relying on it. - Source. Read in Element Plus 2.14.0:
input.vueclear,select/src/useSelect.mjs(useEmptyValues(props)),time-picker/src/common/picker(useEmptyValues(props, null)),input-number(valueOnCleardefaultnull), andhooks/use-empty-values.
A date picker without value-format writes a Date
- Symptom. A date chosen in the form reaches the backend one day early, or as a UTC timestamp such as
2025-12-31T16:00:00.000Zwhen the user picked 1 January in UTC+8. - Cause. Without
value-formatthe picker emits theDateobject itself; itsformatterreturns the value unchanged when no format is set.JSON.stringifyturns aDateinto a UTC ISO string. - Fix. Set
value-format(for exampleYYYY-MM-DD) on every date and date-time picker whose value is sent as is. In a wrapper, put it in the wrapper's defaults rather than on each page. - Source. Read in
es/components/time-picker/src/utils.mjs(formatter) andcomposables/use-common-picker.mjs, Element Plus 2.14.0. The serialization was reproduced in Node withTZ=Asia/Shanghai:JSON.stringify({ d: new Date(2026, 0, 1) })gives2025-12-31T16:00:00.000Z. Other libraries: not checked.
Adapters
| Role | PC · Element Plus | PC · antdv-next | H5 · Vant |
|---|---|---|---|
| After-open (echo) event | @opened; destroy-on-close makes it fire on every open |
@afterOpenChange(open) on Modal, act when open is true; destroyOnHidden unmounts on close; Drawer no longer declares afterOpenChange, see the reference |
popup @opened |
| Close event | @close; fires whenever the dialog starts closing, whatever the cause |
not checked | not checked |
| Form reset | resetFields(); whole-model replacement has a timing rule, see the reference |
resetFields(); store-driven form, unverified, see the reference |
resetValidation() clears validation state only; reset values by replacing the model |
| Value of a cleared control | '' input, undefined select, null date picker and input-number; see the reference |
not checked | not checked |
| Selection after the data array is replaced | cleared, unless reserve-selection and row-key |
not checked | not checked |
| Date picker value | Date object; value-format makes it a string |
not checked | not checked |
Mini-program: not verified; add a column when a real project exists.
References: Element Plus, antdv-next, Vant.