在 Vue 2 中,Element UI 提供了一个 Alert 警告组件,用于显示警告信息。然而,在 Vue 3 中,由于 Element UI 官方并未直接支持,你可能需要使用 Element Plus,这是 Element UI 的 Vue 3 版本。下面,我将分别为 Vue 2 的 Element UI 和 Vue 3 的 Element Plus 介绍 Alert 组件的属性、事件和方法,并给出使用示例。
Vue 2 + Element UI 中的 Alert 组件
属性 (Attributes)
- title: 警告的标题。
- type: 警告的类型,可选值为
success
、warning
、info
、error
。默认为info
。 - description: 警告的描述文字。
- closable: 是否可关闭,默认为
true
。 - close-text: 自定义关闭按钮的文本。
- show-icon: 是否显示图标,默认为
false
。
事件 (Events)
- close: 当 Alert 关闭时会触发该事件。