main.js
中全局引入並註冊import Antd from 'ant-design-vue' import 'ant-design-vue/dist/antd.css' Vue.use(Antd)
<template> <div> <a-button type="primary">hello world</a-button> </div> </template> <script> export default {} </script>
main.js
中導入並註冊須要在項目中使用的組件import { Button } from "ant-design-vue"; import 'ant-design-vue/lib/button/style/css' Vue.component(Button.name, Button)
<template> <div> <a-button type="primary">hello world</a-button> </div> </template> <script> export default {} </script>
ant-design-vue
使用babel-plugin-import
進行按需加載css
babel-plugin-import
插件npm i babel-plugin-import --save-devvue
.babelrc
文件,在plugins
節點下,添加下面這個配置項:"plugins": ["transform-vue-jsx", "transform-runtime", [ "import", { "libraryName": "ant-design-vue", "libraryDirectory": "lib", "style": "css" } ] ]
<template> <div> <a-button type="primary">hello world</a-button> </div> </template> <script> import { Button } from 'ant-design-vue'; export default { components:{ AButton:Button }, } </script>