import { createApp } from 'vue'import App from './App.vue'import router from './router/index'import store from './store/index'import Antd from 'ant-design-vue';import 'ant-design-vue/dist/antd.css';createApp(App).use(Antd).use(router).use(store).mount('#app') //use必须要在mount之前
按需引入,官网没怎么写,估计很多人比力懵
起首将main.js中全局引入的表明掉
安装按需引入插件
npm i unplugin-vue-components -D打开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(), ], }) ],})留意:使用的 Vite,你可以使用unplugin-vue-components来举行按需加载。但是此插件无法处置惩罚非组件模块,如 message,这种组件须要手动加载:
import { message } from 'ant-design-vue';import 'ant-design-vue/es/message/style/css';