时间:2022-07-07 09:50:08 | 栏目:vue | 点击:次
yarn add vite-plugin-style-import -D or npm i vite-plugin-style-import -D
插件仓库地址:github
import vue from '@vitejs/plugin-vue' import styleImport from 'vite-plugin-style-import'; /** * @type {import('vite').UserConfig} */ export default { plugins: [ vue(), styleImport({ libs: [{ libraryName: 'ant-design-vue', esModule: true, resolveStyle: (name) => { return `ant-design-vue/es/${name}/style/css`; }, }] }) ] }
main.js
import { createApp } from 'vue' import App from './App.vue' import { Input } from 'ant-design-vue'; const app=createApp(App) app.use(Input) app.mount('#app')
组件中使用
<template> <!-- script-setup内引入使用,不需注册--> <Button type="primary"> Primary</Button> <!-- 在mian.js使用use注册组件 --> <a-input placeholder="Basic usage" /> </template> <script setup> import { Button } from "ant-design-vue"; </script>