• Element


    Element:是饿了么公司前端开发团队提供的一套基于 Vue 的网站组件库,用于快速构建网页。

    Element 提供了很多组件(组成网页的部件)供我们使用。例如 超链接、按钮、图片、表格等等~

    如下图左边的是我们编写页面看到的按钮,上图右边的是 Element 提供的页面效果,效果一目了然。

    我们学习 Element 其实就是学习怎么从官网拷贝组件到我们自己的页面并进行修改,官网网址是:

    Elementicon-default.png?t=M666https://element.eleme.cn/#/zh-CN

    进入官网能看到如下页面,接下来直接点击 组件 ,页面如下

    一、快速入门

    1. 创建页面,并在页面引入Element cssjs文件 和 Vue.js

    1. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
    2. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    3. <script src="https://unpkg.com/element-ui/lib/index.js">script>

    2. 创建Vue核心对象

    Element 是基于 Vue 的,所以使用Element时必须要创建 Vue 对象

    3. 官网复制Element组件代码

    在左菜单栏找到 Button 按钮 ,然后找到自己喜欢的按钮样式,点击 显示代码 ,在下面就会展示出对应的代码,将这些代码拷贝到我们自己的页面即可。

    整体页面代码如下:

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Titletitle>
    6. head>
    7. <body>
    8. <div id="app">
    9. <el-row>
    10. <el-button>默认按钮el-button>
    11. <el-button type="primary">主要按钮el-button>
    12. <el-button type="success">成功按钮el-button>
    13. <el-button type="info">信息按钮el-button>
    14. <el-button type="warning">警告按钮el-button>
    15. <el-button type="danger">删除el-button>
    16. el-row>
    17. <el-row>
    18. <el-button plain>朴素按钮el-button>
    19. <el-button type="primary" plain>主要按钮el-button>
    20. <el-button type="success" plain>成功按钮el-button>
    21. <el-button type="info" plain>信息按钮el-button>
    22. <el-button type="warning" plain>警告按钮el-button>
    23. <el-button type="danger" plain>危险按钮el-button>
    24. el-row>
    25. <el-row>
    26. <el-button round>圆角按钮el-button>
    27. <el-button type="primary" round>主要按钮el-button>
    28. <el-button type="success" round>成功按钮el-button>
    29. <el-button type="info" round>信息按钮el-button>
    30. <el-button type="warning" round>警告按钮el-button>
    31. <el-button type="danger" round>危险按钮el-button>
    32. el-row>
    33. div>
    34. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
    35. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    36. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    37. <script>
    38. new Vue({
    39. el: "#app"
    40. })
    41. script>
    42. body>
    43. html>

    二、Element 布局

    Element 提供了两种布局方式,分别是:

    • Layout 布局

    • Container 布局容器

    1. Layout 局部

    通过基础的 24 分栏,迅速简便地创建布局。也就是默认将一行分为 24 栏,根据页面要求给每一列设置所占的栏数。

    在左菜单栏找到 Layout 布局 ,然后找到自己喜欢的按钮样式,点击 显示代码 ,在下面就会展示出对应的代码,显示出的代码中有样式,有html标签。将样式拷贝我们自己页面的 head 标签内,将html标签拷贝到

    标签内。

    整体页面代码如下:

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Titletitle>
    6. <style>
    7. .el-row {
    8. margin-bottom: 20px;
    9. }
    10. .el-col {
    11. border-radius: 4px;
    12. }
    13. .bg-purple-dark {
    14. background: #99a9bf;
    15. }
    16. .bg-purple {
    17. background: #d3dce6;
    18. }
    19. .bg-purple-light {
    20. background: #e5e9f2;
    21. }
    22. .grid-content {
    23. border-radius: 4px;
    24. min-height: 36px;
    25. }
    26. .row-bg {
    27. padding: 10px 0;
    28. background-color: #f9fafc;
    29. }
    30. style>
    31. head>
    32. <body>
    33. <div id="app">
    34. <el-row>
    35. <el-col :span="24">
    36. <div class="grid-content bg-purple-dark">div>
    37. el-col>
    38. el-row>
    39. <el-row>
    40. <el-col :span="12">
    41. <div class="grid-content bg-purple">div>
    42. el-col>
    43. <el-col :span="12">
    44. <div class="grid-content bg-purple-light">div>
    45. el-col>
    46. el-row>
    47. <el-row>
    48. <el-col :span="8">
    49. <div class="grid-content bg-purple">div>
    50. el-col>
    51. <el-col :span="8">
    52. <div class="grid-content bg-purple-light">div>
    53. el-col>
    54. <el-col :span="8">
    55. <div class="grid-content bg-purple">div>
    56. el-col>
    57. el-row>
    58. <el-row>
    59. <el-col :span="6">
    60. <div class="grid-content bg-purple">div>
    61. el-col>
    62. <el-col :span="6">
    63. <div class="grid-content bg-purple-light">div>
    64. el-col>
    65. <el-col :span="6">
    66. <div class="grid-content bg-purple">div>
    67. el-col>
    68. <el-col :span="6">
    69. <div class="grid-content bg-purple-light">div>
    70. el-col>
    71. el-row>
    72. <el-row>
    73. <el-col :span="4">
    74. <div class="grid-content bg-purple">div>
    75. el-col>
    76. <el-col :span="4">
    77. <div class="grid-content bg-purple-light">div>
    78. el-col>
    79. <el-col :span="4">
    80. <div class="grid-content bg-purple">div>
    81. el-col>
    82. <el-col :span="4">
    83. <div class="grid-content bg-purple-light">div>
    84. el-col>
    85. <el-col :span="4">
    86. <div class="grid-content bg-purple">div>
    87. el-col>
    88. <el-col :span="4">
    89. <div class="grid-content bg-purple-light">div>
    90. el-col>
    91. el-row>
    92. <el-row>
    93. <el-col :span="3">
    94. <div class="grid-content bg-purple">div>
    95. el-col>
    96. <el-col :span="3">
    97. <div class="grid-content bg-purple-light">div>
    98. el-col>
    99. <el-col :span="3">
    100. <div class="grid-content bg-purple">div>
    101. el-col>
    102. <el-col :span="3">
    103. <div class="grid-content bg-purple-light">div>
    104. el-col>
    105. <el-col :span="3">
    106. <div class="grid-content bg-purple">div>
    107. el-col>
    108. <el-col :span="3">
    109. <div class="grid-content bg-purple-light">div>
    110. el-col>
    111. <el-col :span="3">
    112. <div class="grid-content bg-purple">div>
    113. el-col>
    114. <el-col :span="3">
    115. <div class="grid-content bg-purple-light">div>
    116. el-col>
    117. el-row>
    118. div>
    119. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
    120. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    121. <script src="https://unpkg.com/element-ui/lib/index.js">script>
    122. <script>
    123. new Vue({
    124. el: "#app"
    125. })
    126. script>
    127. body>
    128. html>

    2. Container 布局容器

    用于布局的容器组件,方便快速搭建页面的基本结构。如下图就是布局容器效果。

    如下图是官网提供的 Container 布局容器实例:

    该效果代码中包含了样式、页面标签、模型数据。将里面的样式