码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • elementui的使用以及容易出现的问题


    其实大多数的使用都可以参考官网elementUI官网

    1.安装

    安装的时候需要注意一下,当前的vue版本是2还是3,他们安装的命令有些区别
    vue2

    npm i element-ui -S
    
    • 1

    vue3

    npm install element-plus --save
    
    • 1

    但是我的还是报错了,因为版本冲突,报错信息如下
    在这里插入图片描述

    this command with --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.
    
    • 1

    解决就是在命令行后面加上 --legacy-peer-deps

    npm install element-plus --save --legacy-peer-deps
    
    • 1

    2.引入

    2.1全局引入

    vue2
    import Vue from 'vue';
    import ElementUI from 'element-ui';
    import 'element-ui/lib/theme-chalk/index.css';
    import App from './App.vue';
    
    Vue.use(ElementUI);
    
    new Vue({
      el: '#app',
      render: h => h(App)
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    vue3
    import { createApp } from 'vue'
    import App from './App.vue'
    import store from './store'
    import ElementPlus from 'element-plus';
    import 'element-plus/dist/index.css';
    
    createApp(App).use(ElementPlus).use(store).mount('#app')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2.2按需引入

    vue3
    1.下载插件

    npm install babel-plugin-import -D
    
    • 1

    2.在项目中配置babel.config.js,如果没有则自行创建一个

    module.exports = {
      presets: [
        '@vue/cli-plugin-babel/preset'
      ],
      plugins: [
        [
          'component',
          {
            libraryName: 'element-plus',    // 框架名
            styleLibraryName: 'theme-chalk'  // 样式名称
          }
        ]
      ]
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    3.创建一个plugins文件夹,里面创建一个element.js

    // 引入特定组件及样式
    import 'element-plus/lib/theme-chalk/index.css'
    import {
      ElButton,
      ElContainer,
      ElHeader,
      ElAside,
      ElMain,
    }  from 'element-plus'
    
    //注册特定组件
    const components = [
        ElButton,ElContainer,ElHeader,ElMain,ElAside
    ]
    
    export default (app) => {
        components.forEach(component => {
          app.component(component.name, component)
        })
      }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    4.在入口文件引入element-plus

    import installElementPlus from '@/plugins/element'
    
    const app = createApp(App)
    installElementPlus(app)
    app.mount('#app')
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    5.在vue文件了按需进行使用

    <template>
    	<el-form-item class="button">
    	  <el-button type="primary" @click="showDialog" v-authElement="['templateAdd']">查看市场分析</el-button>
    	</el-form-item>
    </template>
    
    <script>
    import { ElFormItem,ElTable } from 'element-plus'
    export default {
      components: {
        ElFormItem,
        ElTable
      },
    }
    </script>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    在组件中使用的时候直接引入

    import {Button, Upload} from 'element-ui'
    export default {
      components:{
        [Button.name]:Button,
        [Upload.name]:Upload
      },
     }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 相关阅读:
    js创建 ajax 过程
    Python武器库开发-常用模块之subprocess模块(十九)
    mysql 统计当天,当周,当月,当年和总量的SQL语句如何写?
    前端工程搭建:
    【图像隐藏】基于matlab像素预测和位平面压缩的加密图像可逆数据隐藏【含Matlab源码 2218期】
    从零开始构建一个电影知识图谱,实现KBQA智能问答[上篇]:本体建模、RDF、D2RQ、SPARQL endpoint与两种交互方式详细教学
    MATLIB从excel表中读取数据并画出函数图像
    【Linux】常用命令
    「广告」和「噱头」撑得起千亿床垫市场吗?
    Hyper-V 安装windows10 虚拟机,且能调试窗口大小、与主机之间复制文件
  • 原文地址:https://blog.csdn.net/qq_44741441/article/details/127847174
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号