关键词搜索

源码搜索 ×
×

ElementUI腾讯云开发者开发指南

发布2018-12-05浏览2037次

详情内容

原文地址:https://cloud.tencent.com/developer/chapter/18051

目录

安装

npm 安装

CDN

Hello world

快速上手

使用 vue-cli@3

使用 Starter Kit

引入 Element

全局配置

开始使用

使用 Nuxt.js

国际化

兼容 vue-i18n@5.x

兼容其他 i18n 插件

兼容 vue-i18n@6.x

按需加载里定制 i18n

通过 CDN 的方式加载语言文件

自定义主题

仅替换主题色

在项目中改变 SCSS 变量

命令行主题工具

内置过渡动画

fade 淡入淡出

zoom 缩放

collapse 展开折叠

按需引入


安装

npm 安装

推荐使用 npm 的方式安装,它能更好地和 webpack 打包工具配合使用。

npm i element-ui -S

CDN

目前可以通过 unpkg.com/element-ui 获取到最新版本的资源,在页面上引入 js 和 css 文件即可开始使用。

  1. <!-- 引入样式 -->
  2. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  3. <!-- 引入组件库 -->
  4. <script src="https://unpkg.com/element-ui/lib/index.js"></script>

我们建议使用 CDN 引入 Element 的用户在链接地址上锁定版本,以免将来 Element 升级时受到非兼容性更新的影响。锁定版本的方法请查看 unpkg.com

Hello world

通过 CDN 的方式我们可以很容易地使用 Element 写出一个 Hello world 页面。

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <!-- import CSS -->
  6. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  7. </head>
  8. <body>
  9. <div id="app">
  10. <el-button @click="visible = true">Button</el-button>
  11. <el-dialog :visible.sync="visible" title="Hello world">
  12. <p>Try Element</p>
  13. </el-dialog>
  14. </div>
  15. </body>
  16. <!-- import Vue before Element -->
  17. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  18. <!-- import JavaScript -->
  19. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  20. <script>
  21. new Vue({
  22. el: '#app',
  23. data: function() {
  24. return { visible: false }
  25. }
  26. })
  27. </script>
  28. </html>

如果是通过 npm 安装,并希望配合 webpack 使用,请阅读下一节:快速上手。

快速上手

本节将介绍如何在项目中使用 Element。

使用 vue-cli@3

我们为新版的 vue-cli 准备了相应的 Element 插件,你可以用它们快速地搭建一个基于 Element 的项目。

使用 Starter Kit

我们提供了通用的项目模板,你可以直接使用。对于 Laravel 用户,我们也准备了相应的模板,同样可以直接下载使用。

如果不希望使用我们提供的模板,请继续阅读。

引入 Element

你可以引入整个 Element,或是根据需要仅引入部分组件。我们先介绍如何引入完整的 Element。

完整引入

在 main.js 中写入以下内容:

  1. import Vue from 'vue';
  2. import ElementUI from 'element-ui';
  3. import 'element-ui/lib/theme-chalk/index.css';
  4. import App from './App.vue';
  5. Vue.use(ElementUI);
  6. new Vue({
  7. el: '#app',
  8. render: h => h(App)
  9. });

以上代码便完成了 Element 的引入。需要注意的是,样式文件需要单独引入。

按需引入

借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。

首先,安装 babel-plugin-component:

npm install babel-plugin-component -D

然后,将 .babelrc 修改为:

  1. {
  2. "presets": [["es2015", { "modules": false }]],
  3. "plugins": [
  4. [
  5. "component",
  6. {
  7. "libraryName": "element-ui",
  8. "styleLibraryName": "theme-chalk"
  9. }
  10. ]
  11. ]
  12. }

接下来,如果你只希望引入部分组件,比如 Button 和 Select,那么需要在 main.js 中写入以下内容:

  1. import Vue from 'vue';
  2. import { Button, Select } from 'element-ui';
  3. import App from './App.vue';
  4. Vue.component(Button.name, Button);
  5. Vue.component(Select.name, Select);
  6. /* 或写为
  7. * Vue.use(Button)
  8. * Vue.use(Select)
  9. */
  10. new Vue({
  11. el: '#app',
  12. render: h => h(App)
  13. });

完整组件列表和引入方式(完整组件列表以 components.json 为准)

  1. import Vue from 'vue';
  2. import {
  3. Pagination,
  4. Dialog,
  5. Autocomplete,
  6. Dropdown,
  7. DropdownMenu,
  8. DropdownItem,
  9. Menu,
  10. Submenu,
  11. MenuItem,
  12. MenuItemGroup,
  13. Input,
  14. InputNumber,
  15. Radio,
  16. RadioGroup,
  17. RadioButton,
  18. Checkbox,
  19. CheckboxButton,
  20. CheckboxGroup,
  21. Switch,
  22. Select,
  23. Option,
  24. OptionGroup,
  25. Button,
  26. ButtonGroup,
  27. Table,
  28. TableColumn,
  29. DatePicker,
  30. TimeSelect,
  31. TimePicker,
  32. Popover,
  33. Tooltip,
  34. Breadcrumb,
  35. BreadcrumbItem,
  36. Form,
  37. FormItem,
  38. Tabs,
  39. TabPane,
  40. Tag,
  41. Tree,
  42. Alert,
  43. Slider,
  44. Icon,
  45. Row,
  46. Col,
  47. Upload,
  48. Progress,
  49. Badge,
  50. Card,
  51. Rate,
  52. Steps,
  53. Step,
  54. Carousel,
  55. CarouselItem,
  56. Collapse,
  57. CollapseItem,
  58. Cascader,
  59. ColorPicker,
  60. Transfer,
  61. Container,
  62. Header,
  63. Aside,
  64. Main,
  65. Footer,
  66. Loading,
  67. MessageBox,
  68. Message,
  69. Notification
  70. } from 'element-ui';
  71. Vue.use(Pagination);
  72. Vue.use(Dialog);
  73. Vue.use(Autocomplete);
  74. Vue.use(Dropdown);
  75. Vue.use(DropdownMenu);
  76. Vue.use(DropdownItem);
  77. Vue.use(Menu);
  78. Vue.use(Submenu);
  79. Vue.use(MenuItem);
  80. Vue.use(MenuItemGroup);
  81. Vue.use(Input);
  82. Vue.use(InputNumber);
  83. Vue.use(Radio);
  84. Vue.use(RadioGroup);
  85. Vue.use(RadioButton);
  86. Vue.use(Checkbox);
  87. Vue.use(CheckboxButton);
  88. Vue.use(CheckboxGroup);
  89. Vue.use(Switch);
  90. Vue.use(Select);
  91. Vue.use(Option);
  92. Vue.use(OptionGroup);
  93. Vue.use(Button);
  94. Vue.use(ButtonGroup);
  95. Vue.use(Table);
  96. Vue.use(TableColumn);
  97. Vue.use(DatePicker);
  98. Vue.use(TimeSelect);
  99. Vue.use(TimePicker);
  100. Vue.use(Popover);
  101. Vue.use(Tooltip);
  102. Vue.use(Breadcrumb);
  103. Vue.use(BreadcrumbItem);
  104. Vue.use(Form);
  105. Vue.use(FormItem);
  106. Vue.use(Tabs);
  107. Vue.use(TabPane);
  108. Vue.use(Tag);
  109. Vue.use(Tree);
  110. Vue.use(Alert);
  111. Vue.use(Slider);
  112. Vue.use(Icon);
  113. Vue.use(Row);
  114. Vue.use(Col);
  115. Vue.use(Upload);
  116. Vue.use(Progress);
  117. Vue.use(Badge);
  118. Vue.use(Card);
  119. Vue.use(Rate);
  120. Vue.use(Steps);
  121. Vue.use(Step);
  122. Vue.use(Carousel);
  123. Vue.use(CarouselItem);
  124. Vue.use(Collapse);
  125. Vue.use(CollapseItem);
  126. Vue.use(Cascader);
  127. Vue.use(ColorPicker);
  128. Vue.use(Container);
  129. Vue.use(Header);
  130. Vue.use(Aside);
  131. Vue.use(Main);
  132. Vue.use(Footer);
  133. Vue.use(Loading.directive);
  134. Vue.prototype.$loading = Loading.service;
  135. Vue.prototype.$msgbox = MessageBox;
  136. Vue.prototype.$alert = MessageBox.alert;
  137. Vue.prototype.$confirm = MessageBox.confirm;
  138. Vue.prototype.$prompt = MessageBox.prompt;
  139. Vue.prototype.$notify = Notification;
  140. Vue.prototype.$message = Message;

全局配置

在引入 Element 时,可以传入一个全局配置对象。该对象目前支持 sizezIndex 字段。size 用于改变组件的默认尺寸,zIndex 设置弹框的初始 z-index(默认值:2000)。按照引入 Element 的方式,具体操作如下:

完整引入 Element:

  1. import Vue from 'vue';
  2. import Element from 'element-ui';
  3. Vue.use(Element, { size: 'small', zIndex: 3000 });

按需引入 Element:

  1. import Vue from 'vue';
  2. import { Button } from 'element-ui';
  3. Vue.prototype.$ELEMENT = { size: 'small', zIndex: 3000 };
  4. Vue.use(Button);

按照以上设置,项目中所有拥有 size 属性的组件的默认尺寸均为 'small',弹框的初始 z-index 为 3000。

开始使用

至此,一个基于 Vue 和 Element 的开发环境已经搭建完毕,现在就可以编写代码了。各个组件的使用方法请参阅它们各自的文档。

使用 Nuxt.js

我们还可以使用 Nuxt.js

国际化

Element 组件内部默认使用中文,若希望使用其他语言,则需要进行多语言设置。以英文为例,在 main.js 中:

  1. // 完整引入 Element
  2. import Vue from 'vue'
  3. import ElementUI from 'element-ui'
  4. import locale from 'element-ui/lib/locale/lang/en'
  5. Vue.use(ElementUI, { locale })

  1. // 按需引入 Element
  2. import Vue from 'vue'
  3. import { Button, Select } from 'element-ui'
  4. import lang from 'element-ui/lib/locale/lang/en'
  5. import locale from 'element-ui/lib/locale'
  6. // 设置语言
  7. locale.use(lang)
  8. // 引入组件
  9. Vue.component(Button.name, Button)
  10. Vue.component(Select.name, Select)

如果使用其它语言,默认情况下中文语言包依旧是被引入的,可以使用 webpack 的 NormalModuleReplacementPlugin 替换默认语言包。

webpack.config.js

  1. {
  2. plugins: [
  3. new webpack.NormalModuleReplacementPlugin(/element-ui[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]zh-CN/, 'element-ui/lib/locale/lang/en')
  4. ]
  5. }

兼容 vue-i18n@5.x

Element 兼容 vue-i18n@5.x,搭配使用能更方便地实现多语言切换。

  1. import Vue from 'vue'
  2. import VueI18n from 'vue-i18n'
  3. import Element from 'element-ui'
  4. import enLocale from 'element-ui/lib/locale/lang/en'
  5. import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
  6. Vue.use(VueI18n)
  7. Vue.use(Element)
  8. Vue.config.lang = 'zh-cn'
  9. Vue.locale('zh-cn', zhLocale)
  10. Vue.locale('en', enLocale)

兼容其他 i18n 插件

如果不使用 vue-i18n@5.x,而是用其他的 i18n 插件,Element 将无法兼容,但是可以自定义 Element 的 i18n 的处理方法。

  1. import Vue from 'vue'
  2. import Element from 'element-ui'
  3. import enLocale from 'element-ui/lib/locale/lang/en'
  4. import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
  5. Vue.use(Element, {
  6. i18n: function (path, options) {
  7. // ...
  8. }
  9. })

兼容 vue-i18n@6.x

默认不支持 6.x 的 vue-i18n,你需要手动处理。

  1. import Vue from 'vue'
  2. import Element from 'element-ui'
  3. import VueI18n from 'vue-i18n'
  4. import enLocale from 'element-ui/lib/locale/lang/en'
  5. import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
  6. Vue.use(VueI18n)
  7. const messages = {
  8. en: {
  9. message: 'hello',
  10. ...enLocale // 或者用 Object.assign({ message: 'hello' }, enLocale)
  11. },
  12. zh: {
  13. message: '你好',
  14. ...zhLocale // 或者用 Object.assign({ message: '你好' }, zhLocale)
  15. }
  16. }
  17. // Create VueI18n instance with options
  18. const i18n = new VueI18n({
  19. locale: 'en', // set locale
  20. messages, // set locale messages
  21. })
  22. Vue.use(Element, {
  23. i18n: (key, value) => i18n.t(key, value)
  24. })
  25. new Vue({ i18n }).$mount('#app')

按需加载里定制 i18n

  1. import Vue from 'vue'
  2. import DatePicker from 'element/lib/date-picker'
  3. import VueI18n from 'vue-i18n'
  4. import enLocale from 'element-ui/lib/locale/lang/en'
  5. import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
  6. import ElementLocale from 'element-ui/lib/locale'
  7. Vue.use(VueI18n)
  8. Vue.use(DatePicker)
  9. const messages = {
  10. en: {
  11. message: 'hello',
  12. ...enLocale
  13. },
  14. zh: {
  15. message: '你好',
  16. ...zhLocale
  17. }
  18. }
  19. // Create VueI18n instance with options
  20. const i18n = new VueI18n({
  21. locale: 'en', // set locale
  22. messages, // set locale messages
  23. })
  24. ElementLocale.i18n((key, value) => i18n.t(key, value))

通过 CDN 的方式加载语言文件

  1. <script src="//unpkg.com/vue"></script>
  2. <script src="//unpkg.com/element-ui"></script>
  3. <script src="//unpkg.com/element-ui/lib/umd/locale/en.js"></script>
  4. <script>
  5. ELEMENT.locale(ELEMENT.lang.en)
  6. </script>

搭配 vue-i18n 使用

  1. <script src="//unpkg.com/vue"></script>
  2. <script src="//unpkg.com/vue-i18n/dist/vue-i18n.js"></script>
  3. <script src="//unpkg.com/element-ui"></script>
  4. <script src="//unpkg.com/element-ui/lib/umd/locale/zh-CN.js"></script>
  5. <script src="//unpkg.com/element-ui/lib/umd/locale/en.js"></script>
  6. <script>
  7. Vue.locale('en', ELEMENT.lang.en)
  8. Vue.locale('zh-cn', ELEMENT.lang.zhCN)
  9. </script>

目前 Element 内置了以下语言:

  • 简体中文(zh-CN)
  • 英语(en)
  • 德语(de)
  • 葡萄牙语(pt)
  • 西班牙语(es)
  • 丹麦语(da)
  • 法语(fr)
  • 挪威语(nb-NO)
  • 繁体中文(zh-TW)
  • 意大利语(it)
  • 韩语(ko)
  • 日语(ja)
  • 荷兰语(nl)
  • 越南语(vi)
  • 俄语(ru-RU)
  • 土耳其语(tr-TR)
  • 巴西葡萄牙语(pt-br)
  • 波斯语(fa)
  • 泰语(th)
  • 印尼语(id)
  • 保加利亚语(bg)
  • 波兰语(pl)
  • 芬兰语(fi)
  • 瑞典语(sv-SE)
  • 希腊语(el)
  • 斯洛伐克语(sk)
  • 加泰罗尼亚语(ca)
  • 捷克语(cs-CZ)
  • 乌克兰语(ua)
  • 土库曼语(tk)
  • 泰米尔语(ta)
  • 拉脱维亚语(lv)
  • 南非荷兰语(af-ZA)
  • 爱沙尼亚语(ee)
  • 斯洛文尼亚语(sl)
  • 阿拉伯语(ar)
  • 希伯来语(he)
  • 立陶宛语(lt)
  • 蒙古语(mn)
  • 哈萨克斯坦语(kz)
  • 匈牙利语(hu)
  • 罗马尼亚语(ro)
  • 库尔德语(ku)
  • 维吾尔语(ug-CN)
  • 高棉语(km)

如果你需要使用其他的语言,欢迎贡献 PR:只需加一个语言配置文件即可。

自定义主题

Element 默认提供一套主题,CSS 命名采用 BEM 的风格,方便使用者覆盖样式。我们提供了三种方法,可以进行不同程度的样式自定义。

仅替换主题色

如果仅希望更换 Element 的主题色,推荐使用在线主题生成工具。Element 默认的主题色是鲜艳、友好的蓝色。通过替换主题色,能够让 Element 的视觉更加符合具体项目的定位。

使用上述工具,可以很方便地实时预览主题色改变之后的视觉,同时它还可以基于新的主题色生成完整的样式文件包,供直接下载使用(关于如何使用下载的主题包,请参考本节「引入自定义主题」和「搭配插件按需引入组件主题」部分)。

在项目中改变 SCSS 变量

Element 的 theme-chalk 使用 SCSS 编写,如果你的项目也使用了 SCSS,那么可以直接在项目中改变 Element 的样式变量。新建一个样式文件,例如 element-variables.scss,写入以下内容:

  1. /* 改变主题色变量 */
  2. $--color-primary: teal;
  3. /* 改变 icon 字体路径变量,必需 */
  4. $--font-path: '~element-ui/lib/theme-chalk/fonts';
  5. @import "~element-ui/packages/theme-chalk/src/index";

之后,在项目的入口文件中,直接引入以上样式文件即可(无需引入 Element 编译好的 CSS 文件):

  1. import Vue from 'vue'
  2. import Element from 'element-ui'
  3. import './element-variables.scss'
  4. Vue.use(Element)

需要注意的是,覆盖字体路径变量是必需的,将其赋值为 Element 中 icon 图标所在的相对路径即可。

命令行主题工具

如果你的项目没有使用 SCSS,那么可以使用命令行主题工具进行深层次的主题定制:

安装工具

首先安装「主题生成工具」,可以全局安装或者安装在当前项目下,推荐安装在项目里,方便别人 clone 项目时能直接安装依赖并启动,这里以全局安装做演示。

npm i element-theme -g

安装白垩主题,可以从 npm 安装或者从 GitHub 拉取最新代码。

  1. # 从 npm
  2. npm i element-theme-chalk -D
  3. # 从 GitHub
  4. npm i https://github.com/ElementUI/theme-chalk -D

初始化变量文件

主题生成工具安装成功后,如果全局安装可以在命令行里通过 et 调用工具,如果安装在当前目录下,需要通过 node_modules/.bin/et 访问到命令。执行 -i 初始化变量文件。默认输出到 element-variables.scss,当然你可以传参数指定文件输出目录。

  1. et -i [可以自定义变量文件]
  2. > ✔ Generator variables file

如果使用默认配置,执行后当前目录会有一个 element-variables.scss 文件。内部包含了主题所用到的所有变量,它们使用 SCSS 的格式定义。大致结构如下:

  1. $--color-primary: #409EFF !default;
  2. $--color-primary-light-1: mix($--color-white, $--color-primary, 10%) !default; /* 53a8ff */
  3. $--color-primary-light-2: mix($--color-white, $--color-primary, 20%) !default; /* 66b1ff */
  4. $--color-primary-light-3: mix($--color-white, $--color-primary, 30%) !default; /* 79bbff */
  5. $--color-primary-light-4: mix($--color-white, $--color-primary, 40%) !default; /* 8cc5ff */
  6. $--color-primary-light-5: mix($--color-white, $--color-primary, 50%) !default; /* a0cfff */
  7. $--color-primary-light-6: mix($--color-white, $--color-primary, 60%) !default; /* b3d8ff */
  8. $--color-primary-light-7: mix($--color-white, $--color-primary, 70%) !default; /* c6e2ff */
  9. $--color-primary-light-8: mix($--color-white, $--color-primary, 80%) !default; /* d9ecff */
  10. $--color-primary-light-9: mix($--color-white, $--color-primary, 90%) !default; /* ecf5ff */
  11. $--color-success: #67c23a !default;
  12. $--color-warning: #e6a23c !default;
  13. $--color-danger: #f56c6c !default;
  14. $--color-info: #909399 !default;
  15. ...

修改变量

直接编辑 element-variables.scss 文件,例如修改主题色为红色。

$--color-primary: red;

编译主题

保存文件后,到命令行里执行 et 编译主题,如果你想启用 watch 模式,实时编译主题,增加 -w 参数;如果你在初始化时指定了自定义变量文件,则需要增加 -c 参数,并带上你的变量文件名

  1. et
  2. > ✔ build theme font
  3. > ✔ build element theme

引入自定义主题

默认情况下编译的主题目录是放在 ./theme 下,你可以通过 -o 参数指定打包目录。像引入默认主题一样,在代码里直接引用 theme/index.css 文件即可。

  1. import '../theme/index.css'
  2. import ElementUI from 'element-ui'
  3. import Vue from 'vue'
  4. Vue.use(ElementUI)

搭配插件按需引入组件主题

如果是搭配 babel-plugin-component 一起使用,只需要修改 .babelrc 的配置,指定 styleLibraryName 路径为自定义主题相对于 .babelrc 的路径,注意要加 ~

  1. {
  2. "plugins": [["component", [
  3. {
  4. "libraryName": "element-ui",
  5. "styleLibraryName": "~theme"
  6. }
  7. ]]]
  8. }

如果不清楚 babel-plugin-component 是什么,请阅读 快速上手 一节。更多 element-theme 用法请参考项目仓库。

内置过渡动画

Element 内应用在部分组件的过渡动画,你也可以直接使用。在使用之前请阅读 transition 组件文档

fade 淡入淡出

 

 

提供 el-fade-in-linearel-fade-in 两种效果。

  1. <template>
  2. <div>
  3. <el-button @click="show = !show">Click Me</el-button>
  4. <div style="display: flex; margin-top: 20px; height: 100px;">
  5. <transition name="el-fade-in-linear">
  6. <div v-show="show" class="transition-box">.el-fade-in-linear</div>
  7. </transition>
  8. <transition name="el-fade-in">
  9. <div v-show="show" class="transition-box">.el-fade-in</div>
  10. </transition>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data: () => ({
  17. show: true
  18. })
  19. }
  20. </script>
  21. <style>
  22. .transition-box {
  23. margin-bottom: 10px;
  24. width: 200px;
  25. height: 100px;
  26. border-radius: 4px;
  27. background-color: #409EFF;
  28. text-align: center;
  29. color: #fff;
  30. padding: 40px 20px;
  31. box-sizing: border-box;
  32. margin-right: 20px;
  33. }
  34. </style>

zoom 缩放

 

 

提供 el-zoom-in-centerel-zoom-in-topel-zoom-in-bottom 三种效果。

  1. <template>
  2. <div>
  3. <el-button @click="show2 = !show2">Click Me</el-button>
  4. <div style="display: flex; margin-top: 20px; height: 100px;">
  5. <transition name="el-zoom-in-center">
  6. <div v-show="show2" class="transition-box">.el-zoom-in-center</div>
  7. </transition>
  8. <transition name="el-zoom-in-top">
  9. <div v-show="show2" class="transition-box">.el-zoom-in-top</div>
  10. </transition>
  11. <transition name="el-zoom-in-bottom">
  12. <div v-show="show2" class="transition-box">.el-zoom-in-bottom</div>
  13. </transition>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. data: () => ({
  20. show2: true
  21. })
  22. }
  23. </script>
  24. <style>
  25. .transition-box {
  26. margin-bottom: 10px;
  27. width: 200px;
  28. height: 100px;
  29. border-radius: 4px;
  30. background-color: #409EFF;
  31. text-align: center;
  32. color: #fff;
  33. padding: 40px 20px;
  34. box-sizing: border-box;
  35. margin-right: 20px;
  36. }
  37. </style>

collapse 展开折叠

使用 el-collapse-transition 组件实现折叠展开效果。

 

 

  1. <template>
  2. <div>
  3. <el-button @click="show3 = !show3">Click Me</el-button>
  4. <div style="margin-top: 20px; height: 200px;">
  5. <el-collapse-transition>
  6. <div v-show="show3">
  7. <div class="transition-box">el-collapse-transition</div>
  8. <div class="transition-box">el-collapse-transition</div>
  9. </div>
  10. </el-collapse-transition>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data: () => ({
  17. show3: true
  18. })
  19. }
  20. </script>
  21. <style>
  22. .transition-box {
  23. margin-bottom: 10px;
  24. width: 200px;
  25. height: 100px;
  26. border-radius: 4px;
  27. background-color: #409EFF;
  28. text-align: center;
  29. color: #fff;
  30. padding: 40px 20px;
  31. box-sizing: border-box;
  32. margin-right: 20px;
  33. }
  34. </style>

按需引入

  1. // fade/zoom 等
  2. import 'element-ui/lib/theme-chalk/base.css';
  3. // collapse 展开折叠
  4. import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
  5. import Vue from 'vue'
  6. Vue.component(CollapseTransition.name, CollapseTransition)

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载