Home > Web Front-end > Vue.js > How to use Vue3 and Element Plus to implement automatic import

How to use Vue3 and Element Plus to implement automatic import

WBOY
Release: 2023-05-22 16:58:07
forward
2009 people have browsed it

    1 Preface

    1.1 Purpose

    Element Plus uses on-demand introduction to greatly reduce the size of the packaged files

    1.2 Final effect

    Automatically generate the components.d.ts file, and introduce the Element Plus component into the file

    How to use Vue3 and Element Plus to implement automatic import

    ##Automatically generate the components.d.ts file , and introduce Element Plus API in the file

    How to use Vue3 and Element Plus to implement automatic import##2 Preparation work

    Install Element Plus

    # 选择一个你喜欢的包管理器
    
    # NPM
    $ npm install element-plus --save
    
    # Yarn
    $ yarn add element-plus
    
    # pnpm
    $ pnpm install element-plus
    Copy after login

    3 Import on demand

    3.1 Install plug-ins

      Components introduce required plug-ins on demand: unplugin-auto-import, unplugin-vue-components
    • icons Introduce the required plug-ins on demand: unplugin-auto-import, unplugin-icons
    Only need to install to the development environment

    $ pnpm i unplugin-auto-import unplugin-vue-components unplugin-icons -D
    Copy after login

    3.2 Modify vite .config.ts file

    How to use Vue3 and Element Plus to implement automatic import4 Others

    4.1 ELMessage pop-up style does not take effect

    How to use Vue3 and Element Plus to implement automatic import

    You need to manually import the corresponding style of ElMessage. If you only use the component API to cause the style failure problem, you can try the same processing method

    // 示例
    import { ElMessage } from 'element-plus'
    import 'element-plus/es/components/message/style/css'
    Copy after login

    4.2 Icon usage

    Note, -ep - It is configured in the vite.config.ts file and must be consistent

    <!-- 直接使用 -->
    <i-ep-menu />
    
    <!-- 嵌套使用 -->
    <el-icon><i-ep-menu /></el-icon>
    Copy after login

    The above is the detailed content of How to use Vue3 and Element Plus to implement automatic import. For more information, please follow other related articles on the PHP Chinese website!

    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template