This document will help you upgrade from ant-design-vue 3.x
version to ant-design-vue 4.x
version. If you are using 2.x
or older version, please refer to the previous upgrade document to 3.x.
- Please upgrade to the latest version of 3.x first, and remove / modify related APIs according to the console warning message.
- Basic rounded corner adjustment, changed from
2px
to four layers of radius, which are2px
4px
6px
and8px
. For example, radius of default Button is modified from2px
to6px
. - Primary color adjustment, changed from
#1890ff
to#1677ff
. - Global shadow optimization, adjusted from three layers of shadows to two layers, which are used in common components (Card .e.g) and popup components (Dropdown .e.g).
- Overall reduction in wireframe usage.
- Remove less, adopt CSS-in-JS, for better support of dynamic themes.
- All less files are removed, and less variables are no longer exported.
- Css files are no longer included in package. Since CSS-in-JS supports importing on demand, the original
ant-design-vue/dist/antd.css
has also been abandoned. If you need to reset some basic styles, please important-design-vue/dist/reset.css
. - If you need to reset the style of the component, but you don't want to introduce
ant-design-vue/dist/reset.css
to pollute the global style, You can try using the App in the outermost layer to solve the problem that native elements do not have antd specification style.
- Remove css variables and dynamic theme built on top of them.
- LocaleProvider has been deprecated in 3.x (use
<ConfigProvider locale />
instead), we removed the related folderant-design-vue/es/locale-provider
andant-design-vue/lib/locale-provider
in 4.x. - Replace built-in Moment.js with Dayjs. For more: Use custom date library.
babel-plugin-import
is no longer supported. CSS-in-JS itself has the ability to import on demand, and plugin support is no longer required.
- DO NOT support IE browser anymore.
-
The classname API of the component popup box is unified to
popupClassName
, anddropdownClassName
and other similar APIs will be replaced.- AutoComplete
- Cascader
- Select
- TreeSelect
- TimePicker
- DatePicker
- Mentions
<template>
<a-select
-- dropdownClassName="my-select-popup"
++ popupClassName="my-select-popup"
/>
</template>
-
The controlled visible API of the component popup is unified to
open
, andvisible
and other similar APIs will be replaced.- Drawer
visible
changed toopen
. - Modal
visible
changed toopen
. - Dropdown
visible
changed toopen
. - Tooltip
visible
changed toopen
. - Tag
visible
is removed. - Slider
tooltip
related API converged totooltip
property. - Table
filterDropdownVisible
changed tofilterDropdownOpen
.
- Drawer
<template>
-- <a-modal :visible="visible">content</a-modal>
++ <a-modal :open="visible">content</a-modal>
-- <a-tag :visible="visible">tag</a-tag>
++ <a-tag v-if="visible">tag</a-tag>
<a-table
:data="[]"
:columns="[
{
title: 'Name',
dataIndex: 'name',
-- filterDropdownVisible: visible,
++ filterDropdownOpen: visible,
},
]"
/>
-- <a-slider :tooltipVisible="visible" />
++ <a-slider :tooltip="{ open: visible }" />
</template>
<script setup>
import { ref } from 'vue';
const visible = ref(true);
</script>
getPopupContainer
: AllgetPopupContainer
are guaranteed to return a unique div.- Drawer
style
&class
are migrated to Drawer panel node, the original properties are replaced byrootClassName
androotStyle
.
- Remove
locale-provider
Directory.LocaleProvider
was removed in v4, please useConfigProvider
instead. - Remove the
xxxl
breakpoint property from the grid layout.xxxl
breakpoint has been removed in v4. You can customize breakpoint values using theme customization withscreen[XS|SM|MD|LG|XL|XXL]
properties. - BackTop is deprecated in
4.0.0
, and is merged into FloatButton.
Use git to save your code and install latest version:
npm install --save ant-design-vue@4
If you using ant-design-vue less variables, you can use compatible package to covert it into v3 less variables and use less-loader to inject them:
const { theme } = require('ant-design-vue/lib');
const convertLegacyToken = require('ant-design-vue/lib/theme/convertLegacyToken');
const { defaultAlgorithm, defaultSeed } = theme;
const mapToken = defaultAlgorithm(defaultSeed);
const v3Token = convertLegacyToken(mapToken);
// Webpack Config
module.exports = {
// ... other config
loader: 'less-loader',
options: {
lessOptions: {
modifyVars: v3Token,
},
},
};
Ant then remove ant-design-vue less reference in your less file:
// Your less file
-- @import (reference) '~ant-design-vue/es/style/themes/index';
or
-- @import '~ant-design-vue/es/style/some-other-less-file-ref';
Remove babel-plugin-import
from package.json and modify .babelrc
:
"plugins": [
-- ["import", { "libraryName": "ant-design-vue", "libraryDirectory": "lib"}, "ant-design-vue"],
]
Ant Design Vue v4 using :where
css selector to reduce CSS-in-JS hash priority. You can use StyleProvider
to cancel this function. Please ref Compatible adjustment.
If you encounter problems during the upgrade, please go to GitHub issues for feedback. We will respond and improve this document as soon as possible.