前言
在 Vue 开发过程中,我们经常会遇到这样的警告信息:
[Vue warn]: Invalid prop: validation failed for prop "type". Expected one of ["default", "primary", "success", "warning", "info", "danger", "text", ""], got value "warn".
这个警告看似简单,但背后涉及了 Vue 组件设计的核心概念——Prop 验证机制。本文将从这个具体的错误出发,深入探讨 Vue 组件开发中的属性验证最佳实践。
一、错误场景还原
1.1 错误发生的位置
EsOrderList.vue:114 [Vue warn]: Invalid prop: validation failed for prop "type". Expected one of ["default", "primary", "success", "warning", "info", "danger", "text", ""], got value "warn".
这个警告提示我们:
- 文件位置:
EsOrderList.vue的第 114 行 - 问题属性:
type - 期望值:8 种预设值(default/primary/success/warning/info/danger/text/空字符串)
- 实际值:
"warn"
1.2 常见的触发场景
<!-- 错误用法:在 Element UI 按钮组件中使用 -->
<el-button type="warn">确认提交</el-button>
<el-tag =>待处理
3
确认提交
待处理
3


