Import / Export Scaffold
Scenario
This example demonstrates the complete workflow for CSV template download, data import validation, result statistics, and error report export.
- Route:
/examples/import-export - Page:
src/views/examples/scaffold/import-export/index.vue
Core Capabilities
- Import template download (unified field headers)
- CSV import parsing and field validation (required, numeric range, integer validation)
- Incremental update by business key (update if exists, create if not)
- Import summary statistics (total, success, updated, failed)
- Error report export (row number + reason + original content)
Implementation Best Practices
- Define a unique key (e.g.,
code) to standardize "create/update" logic. - Validation failures should return precise row numbers for easy correction.
- Validate template version before import to avoid field mismatches with legacy templates.
- For large-scale imports, switch to async tasks with progress tracking.
Recommended Workflow
- Download template and fill in data.
- Upload CSV and validate headers first.
- Parse and validate each row's field legality.
- Summarize success/failure results and notify user.
- Export error report for secondary correction and re-import.
