当前位置:   article > 正文

Element UI 及 Element Plus框架

element plus

一,何为Element UI 及 Element Plus?

  1. 它们是前端框架。它是包含很多有自己风格的组件库。 
  2. Element目前有两个版本:element-ui 及 element-plus两个版本。
  3. 它将HTML的基础控件进行了封装,用户只需要调用这些控件就可以了。而不需要用CSS去调整风格。
  4. Element UI是一款基于Vue2.x 的界面框架;Element Plus是一款基于Vue3.x 的界面框架;
  5. 既然基于Vue,所以可以使用打包工具打包,例如 Vite或WePack 

  6. 当然Element UI与有React及Angular的版本了。

二、Element UI 与 Element Plus区别?

  1. Element UI框架的升级版(3.x)是Element Plus;Element Plus 目前还处于快速开发迭代中
  2. 由于 Vue 3 不再支持 IE11,Element Plus 也不再支持 IE 浏览器
  3.  Element-Plus 已经把vue的版本锁定了3.x;而Element UI是基于Vue 2.

三、Element UI 与 Element Plus使用

       方式一、直接引用方式,引用其CSS及JS,还有vue.js即可:        

  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@2/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加载,以下以Vue3.0为例:

1,创建一个Vue CLI项目:

2,添加element plus引用:        

  1. import { createApp } from 'vue'
  2. import ElementPlus from 'element-plus'
  3. import 'element-plus/dist/index.css'
  4. //import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
  5. import en from 'element-plus/dist/locale/en.mjs'
  6. import App from './App.vue'
  7. const app = createApp(App)
  8. //切换控件内部的语言
  9. app.use(ElementPlus, {
  10. // locale:zhCn,
  11. locale:en,
  12. })
  13. app.mount('#app')

3,创建一个控件Helloworld.vue:

  1. <template>
  2. <div>
  3. <el-calendar v-model="value" />
  4. </div>
  5. </template>
  6. import { ref } from 'vue'
  7. export default {
  8. name: 'HelloWorld',
  9. data: function() {
  10. return {
  11. value: ref(new Date())
  12. }
  13. },
  14. props: {
  15. msg: String
  16. }
  17. }

4,调用Helloworld.vue:

  1. <template>
  2. <HelloWorld msg="Welcome to Your Vue.js App"/>
  3. </template>
  4. <script>
  5. import HelloWorld from './components/HelloWorld.vue'
  6. export default{
  7. name: 'App',
  8. components: {
  9. HelloWorld
  10. }
  11. }
  12. </script>

结果:

注意:

1,使用element plus的时候,发现有些组件不能使用。查到问题,发现script加了lang="ts".

<script lang="ts" setup>

这个是说明这个组件是基于typescript的。去掉这个 lang="ts",很多组件还是可以用的。

2,本人也尝试过安装typescript,但发现安装这个以后,语法需要遵循typescript的语法,且会自动将js文件变成.ts文件。不习惯,所以我又卸载了。

3,vue3.x支持使用export或<script stepup>的方式。但有些初始化数据,还是需要使用<script stepup>(不然会报错):

例如:

  1. <template>
  2. <el-table :data="tableData" style="width: 100%">
  3. <el-table-column prop="date" label="Date" width="180" />
  4. <el-table-column prop="name" label="Name" width="180" />
  5. <el-table-column prop="address" label="Address" />
  6. </el-table>
  7. </template>
  8. <script setup>
  9. const tableData = [
  10. {
  11. date: '2016-05-03',
  12. name: 'Tom',
  13. address: 'No. 189, Grove St, Los Angeles',
  14. },
  15. {
  16. date: '2016-05-02',
  17. name: 'Tom',
  18. address: 'No. 189, Grove St, Los Angeles',
  19. },
  20. {
  21. date: '2016-05-04',
  22. name: 'Tom',
  23. address: 'No. 189, Grove St, Los Angeles',
  24. },
  25. {
  26. date: '2016-05-01',
  27. name: 'Tom',
  28. address: 'No. 189, Grove St, Los Angeles',
  29. }
  30. ]
  31. </script>

调用:

  1. import {createRouter, createWebHashHistory} from "vue-router";
  2. const routes = [
  3. {
  4. path: "/",
  5. component: () => import("../views/HomePage.vue")
  6. },
  7. {
  8. path: "/home",
  9. component: () => import("../views/HomePage.vue")
  10. },
  11. {
  12. path: "/vip",
  13. component: () => import("../views/VipPage.vue")
  14. },
  15. {
  16. path: "/404",
  17. component: () => import("../views/ErrorPage.vue")
  18. },
  19. {
  20. path: "/:catchAll(.*)", // 不识别的path自动匹配404
  21. redirect: '/404',
  22. },
  23. ]
  24. const router=createRouter({
  25. history: createWebHashHistory(),
  26. routes
  27. })
  28. export default router;

结果:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/116806?site
推荐阅读
相关标签
  

闽ICP备14008679号