Element UI 是一个基于 Vue.js 的 UI 组件库,提供了丰富的组件和功能,可以帮助开发者快速构建美观、交互性强的用户界面。使用 Element UI 可以参考以下步骤:
- 安装:推荐使用 npm 方式安装,在终端中运行
npm i element-ui -S
命令。 - 引入:
- 全局引入:会把组件库里所有的组件和 css 引入,在 Vue.js 的入口文件中使用
import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI);
。 - 局部引入(推荐):在 Vue 的入口 js 里直接引入主题样式
element-variables.css
,使用import '@/style/theme/element-variables.{insert\_element\_1\_c2Nzcw==}'
。然后按需引入组件,使用import { Message, MessageBox, Loading } from 'element-ui' Vue.use(Loading.directive) Vue.prototype.$loading = Loading.service Vue.prototype.$msgbox = MessageBox Vue.prototype.$alert = MessageBox.alert Vue.prototype.$confirm = MessageBox.confirm Vue.prototype.$prompt = MessageBox.prompt Vue.prototype.$message = Message
。
- 全局引入:会把组件库里所有的组件和 css 引入,在 Vue.js 的入口文件中使用
- 组件使用:
- 像
message
、messagebox
弹窗组件是直接挂载全局,可以在 Vue instance 中采用本页面中的方式调用MessageBox
。调用参数为:$msgbox(options)
、$alert(message, title, options)
、$confirm(message, title, options)
、$prompt(message, title, options)
。 - 官网提供的
dialog
组件支持内容区更丰富的写法,dialog
弹出一个对话框,适合需要定制性更大的场景。 鹏仔前端 https://www.pjxi.com/
- 像