1

官网文档

安装antdv

yarn add ant-design-vue@next

Vite配置按需导入

  1. 安装vite按需导入插件 yarn add -D unplugin-vue-components;vite-plugin-components插件已renamed to unplugin-vue-components
  2. 配置vite.config.js:

    import { defineConfig } from 'vite'
    import vue from '@vitejs/plugin-vue'
    import Components from 'unplugin-vue-components/vite'
    import {AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
    
    // https://vitejs.dev/config/
    export default defineConfig({
    plugins: [
     vue(),
     Components({
     resolvers: [
       AntDesignVueResolver()
     ],
     dts: true, // enabled by default if `typescript` is installed
     })
    ]
    })
    
  3. 组件无需导入使用(import HelloWorld被注释)

    <script setup>
    // This starter template is using Vue 3 <script setup> SFCs
    // Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
    // import HelloWorld from './components/HelloWorld.vue'
    </script>
    
    <template>
     <img alt="Vue logo" src="./assets/logo.png" />
     <HelloWorld msg="Hello Vue 3 + Vite" />
     <p>按需导入</p>
    </template>
    
    <style>
    #app {
     font-family: Avenir, Helvetica, Arial, sans-serif;
     -webkit-font-smoothing: antialiased;
     -moz-osx-font-smoothing: grayscale;
     text-align: center;
     color: #2c3e50;
     margin-top: 60px;
    }
    </style>

Must
32 声望1 粉丝

永远不放弃技术(^_^)~~~