欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Element Plus组件-按钮、图标、ColorPicker 颜色选择器、日历、Rate评分、Switch 开关

程序员文章站 2022-03-24 09:40:19
...

Element Plus组件

——按钮、图标、ColorPicker 颜色选择器、日历、Rate评分、Switch 开关

安装 Element Plus

npm install element-plus --save

  • main.js 全局引用
  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. import ElementPlus from 'element-plus'
  4. import 'element-plus/dist/index.css'
  5. const app = createApp(App)
  6. app.use(ElementPlus)
  7. app.mount('#app')

安装icon

npm install @element-plus/icons

App.vue

  1. <template>
  2. <div>
  3. <div>
  4. <h2>按钮图标</h2>
  5. <el-button type="primary">Primary</el-button>
  6. <el-button type="success" circle>
  7. <div style="width: 20px; height: 20px"><edit></edit></div>
  8. </el-button>
  9. </div>
  10. <div style="font-size: 20px">
  11. <edit style="width: 1em; height: 1em; margin-right: 8px" />
  12. <delete style="width: 1em; height: 1em; margin-right: 8px" />
  13. <search style="width: 1em; height: 1em; margin-right: 8px" />
  14. <moon style="width: 1em; height: 1em; margin-right: 8px" />
  15. <message style="width: 1em; height: 1em; margin-right: 8px" />
  16. <star style="width: 1em; height: 1em; margin-right: 8px" />
  17. <Avatar style="width: 1em; height: 1em; margin-right: 8px" />
  18. <Bicycle style="width: 1em; height: 1em; margin-right: 8px" />
  19. </div>
  20. <div>
  21. <div class="demo-color-block">
  22. <h2>ColorPicker 颜色选择器</h2>
  23. <el-color-picker v-model="color" show-alpha />
  24. </div>
  25. </div>
  26. <div>
  27. <div class="block">
  28. <h2>日历</h2>
  29. <el-date-picker v-model="value1" type="date" placeholder="Pick a day">
  30. </el-date-picker>
  31. </div>
  32. </div>
  33. <div>
  34. <h2>Rate评分</h2>
  35. <el-rate v-model="ratevalue" allow-half />
  36. </div>
  37. <div>
  38. <h2>Switch 开关</h2>
  39. <el-switch
  40. v-model="switchvalue"
  41. active-color="#13ce66"
  42. inactive-color="#ff4949"
  43. />
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { defineComponent, ref, reactive, toRefs } from "vue";
  49. import {
  50. Search,
  51. Edit,
  52. Check,
  53. Message,
  54. Star,
  55. Delete,
  56. ElIcon,
  57. Moon,
  58. Avatar,
  59. Bicycle,
  60. } from "@element-plus/icons";
  61. export default defineComponent({
  62. setup() {
  63. const state = reactive({
  64. disabledDate(time) {
  65. return time.getTime() > Date.now();
  66. },
  67. value1: "",
  68. });
  69. const color = ref("rgba(13,100,102,0.8)");
  70. return {
  71. color,
  72. ...toRefs(state),
  73. ratevalue: ref(null),
  74. };
  75. },
  76. components: {
  77. // 图标插件
  78. Search,
  79. Edit,
  80. Check,
  81. Message,
  82. Star,
  83. Delete,
  84. ElIcon,
  85. Moon,
  86. Avatar,
  87. Bicycle,
  88. },
  89. data() {
  90. return {
  91. switchvalue: true,
  92. };
  93. },
  94. });
  95. </script>
  96. <style lang="less"></style>
  • 效果图

Element Plus组件-按钮、图标、ColorPicker 颜色选择器、日历、Rate评分、Switch 开关