在 Vue 2 中,Element UI 提供了 MessageBox
弹框组件,用于显示消息提示、确认消息和获取用户输入等。而在 Vue 3 的 Element Plus 中,虽然组件和 API 可能有所变化,但基本概念和用法是相似的。下面我将分别介绍 Vue 2 的 Element UI 和 Vue 3 的 Element Plus 中 MessageBox
的使用方式。
Vue 2 + Element UI
在 Vue 2 中,Element UI 的 MessageBox
组件是通过 this.$confirm
、this.$alert
、this.$prompt
等全局方法调用的,而不是直接在模板中作为组件使用。
方法
this.$confirm(message, title, options)
: 显示一个确认弹框。this.$alert(message, title, options)
: 显示一个警告弹框。this.$prompt(message, title, options)
: 显示一个带输入框的弹框。
options 参数:
type
: 消息类型,如success
、warning
、info
、error
。title
: 标题。message
: 消息内容。callback
: 回调函数,当用户点击确定或取消按钮时触发。- 其