vuetify-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesevuetify@4.0.1
vuetify@4.0.1
Material Design component framework for Vue 3. Source citations like refer to the prepared package ().
lib/framework.js:15vuetify@4.0.1package.json:4基于 Vue 3 的 Material Design 组件框架。类似 的源码引用指向已准备好的 包()。
lib/framework.js:15vuetify@4.0.1package.json:4Environment limits
环境限制
- Vue peer dependency (
^3.5.0). No Vue 2 support; Vuetify 2 is EOL (package.json:208).README.md:274 - ESM only: (
"type": "module").package.json:32 - Optional peers: ,
vite-plugin-vuetify >=2.1.0,webpack-plugin-vuetify >=3.1.0(typescript >=4.7).package.json:205 - Modern browsers, Safari 13+ with polyfills, minimum design width 320px ().
README.md:159 - Default font is Roboto; you must add it yourself, e.g. (https://vuetifyjs.com/getting-started/installation/).
@fontsource/roboto
- Vue peer dependency(
^3.5.0)。不支持 Vue 2;Vuetify 2 已进入 EOL(package.json:208)。README.md:274 - 仅支持 ESM:(
"type": "module")。package.json:32 - 可选 peer dependencies:、
vite-plugin-vuetify >=2.1.0、webpack-plugin-vuetify >=3.1.0(typescript >=4.7)。package.json:205 - 支持现代浏览器;Safari 13+ 需使用 polyfill;最小设计宽度为 320px()。
README.md:159 - 默认字体为 Roboto;需要自行添加,例如 (https://vuetifyjs.com/getting-started/installation/)。
@fontsource/roboto
Setup
设置
Vite with automatic treeshaking (preferred). The vuetify plugin must come after the vue plugin:
js
// vite.config.js
import vue from '@vitejs/plugin-vue'
import vuetify from 'vite-plugin-vuetify'
export default defineConfig({ plugins: [vue(), vuetify()] })js
// src/plugins/vuetify.js
import 'vuetify/styles'
import { createVuetify } from 'vuetify'
export default createVuetify({
// components, directives not needed with the loader plugin
})Without a loader plugin, register manually; wildcard imports include everything and slow development builds:
js
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
createVuetify({ components, directives })createVuetifyaliasesblueprintcomponentsdatedefaultsdirectivesdisplaygoToiconslocalessrtheme{ install, unmount, defaults, display, theme, icons, locale, date, goTo }lib/framework.js:15app.use(vuetify)<v-app>For SSR frameworks (Nuxt, vite-ssr) set so display values render correctly (https://vuetifyjs.com/getting-started/installation/).
ssr: trueScaffolding: / ().
pnpm create vuetifynpm create vuetify@latestREADME.md:44CDN bundle with everything included: ().
vuetify/dist/vuetify.jspackage.json:35使用 Vite 并自动进行 treeshaking(推荐)。vuetify 插件必须位于 vue 插件之后:
js
// vite.config.js
import vue from '@vitejs/plugin-vue'
import vuetify from 'vite-plugin-vuetify'
export default defineConfig({ plugins: [vue(), vuetify()] })js
// src/plugins/vuetify.js
import 'vuetify/styles'
import { createVuetify } from 'vuetify'
export default createVuetify({
// components, directives not needed with the loader plugin
})不使用 loader plugin 时,需要手动注册;通配符导入会包含所有内容,并降低开发构建速度:
js
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
createVuetify({ components, directives })createVuetifyaliasesblueprintcomponentsdatedefaultsdirectivesdisplaygoToiconslocalessrtheme{ install, unmount, defaults, display, theme, icons, locale, date, goTo }lib/framework.js:15app.use(vuetify)<v-app>对于 SSR 框架(Nuxt、vite-ssr),设置 ,以确保 display 值能够正确渲染(https://vuetifyjs.com/getting-started/installation/)。
ssr: true项目脚手架: / ()。
pnpm create vuetifynpm create vuetify@latestREADME.md:44包含全部内容的 CDN bundle:()。
vuetify/dist/vuetify.jspackage.json:35Components
组件
- Prefer imports from over
vuetify/components/<Group>(loads only needed styles in dev).vuetify/components - Labs components are NOT production ready; import from or
vuetify/labs/<Name>. In 4.0.1 labs holds: VAvatarGroup, VColorInput, VCommandPalette, VDateInput, VFileUpload, VIconBtn, VMaskInput, VPicker, VPie, VStepperVertical, VPullToRefresh, VVideo (vuetify/labs/components).lib/labs/components.js:1 - Dynamic is invisible to the loader plugin; import those components manually (https://vuetifyjs.com/features/treeshaking/).
<component :is> - Full inventory and export paths: references/exports.md
- 优先从 导入,而不是从
vuetify/components/<Group>导入,这样在开发环境中只会加载所需样式。vuetify/components - Labs 组件尚不适用于生产环境;从 或
vuetify/labs/<Name>导入。4.0.1 中的 labs 包含:VAvatarGroup、VColorInput、VCommandPalette、VDateInput、VFileUpload、VIconBtn、VMaskInput、VPicker、VPie、VStepperVertical、VPullToRefresh、VVideo(vuetify/labs/components)。lib/labs/components.js:1 - loader plugin 无法识别动态 ;需要手动导入这些组件(https://vuetifyjs.com/features/treeshaking/)。
<component :is> - 完整清单和导出路径:references/exports.md
Configuration
配置
- Theme: the v4 default is (follows
system), notprefers-color-scheme(light). Pin it withlib/composables/theme.js:10if system switching is unwanted.theme: { defaultTheme: 'light' } - Defaults: set prop defaults per component with .
createVuetify({ defaults: { VBtn: { ... } } })andclasswork only on component keys, never in thestylekey (https://vuetifyjs.com/features/global-configuration/).global - Display: v4 breakpoints changed; defaults are (
sm 600, md 840, lg 1145, xl 1545, xxl 2138).lib/composables/display.js:10 - Icons: default set is and expects the
mdistylesheet, or use@mdi/fontfor bundled SVG icons (https://vuetifyjs.com/features/icon-fonts/).mdi-svg - Dates: default adapter wraps native ; swap with any date-io adapter (https://vuetifyjs.com/features/dates/).
Date - Blueprints: applies a design-system preset; explicit options override the blueprint (
createVuetify({ blueprint: md3 }),lib/framework.js:15).lib/blueprints/index.js:1 - Details and examples: references/configuration.md
- 主题:v4 的默认主题是 (遵循
system),而不是prefers-color-scheme(light)。如果不需要跟随系统切换,请使用lib/composables/theme.js:10固定主题。theme: { defaultTheme: 'light' } - Defaults:通过 按组件设置 prop 默认值。
createVuetify({ defaults: { VBtn: { ... } } })和class仅适用于组件键,绝不能放在style键中(https://vuetifyjs.com/features/global-configuration/)。global - Display:v4 的断点发生了变化;默认值为 (
sm 600, md 840, lg 1145, xl 1545, xxl 2138)。lib/composables/display.js:10 - 图标:默认图标集为 ,需要引入
mdi样式表;也可以使用@mdi/font获取内置的 SVG 图标(https://vuetifyjs.com/features/icon-fonts/)。mdi-svg - 日期:默认适配器封装原生 ;也可以替换为任意 date-io 适配器(https://vuetifyjs.com/features/dates/)。
Date - Blueprints:会应用设计系统预设;显式设置的选项优先于 blueprint(
createVuetify({ blueprint: md3 })、lib/framework.js:15)。lib/blueprints/index.js:1 - 详细信息和示例:references/configuration.md
Composables
Composables
All exported from the entry point (): , , , , , , , , , .
vuetifylib/composables/index.js:1useDateuseDefaultsuseDisplayuseGoTouseLayoutuseLocaleuseRtluseThemeuseHotkeyuseMaskvue
<script setup>
import { useTheme } from 'vuetify'
const theme = useTheme()
theme.toggle() // light <-> dark
</script>For hotkeys prefer the modifier (); it resolves to Command on Mac and Control elsewhere ().
cmduseHotkey('cmd+s', save)lib/composables/hotkey/key-aliases.js:10Full API per composable: references/composables.md
所有 composables 均从 入口点导出():、、、、、、、、、。
vuetifylib/composables/index.js:1useDateuseDefaultsuseDisplayuseGoTouseLayoutuseLocaleuseRtluseThemeuseHotkeyuseMaskvue
<script setup>
import { useTheme } from 'vuetify'
const theme = useTheme()
theme.toggle() // light <-> dark
</script>快捷键应优先使用 修饰符();在 Mac 上会解析为 Command,在其他平台上会解析为 Control()。
cmduseHotkey('cmd+s', save)lib/composables/hotkey/key-aliases.js:10每个 composable 的完整 API:references/composables.md
Styles
样式
- is the all-in-one precompiled CSS; modular entries are
import 'vuetify/styles'(must be first),vuetify/styles/core,vuetify/styles/colors(vuetify/styles/utilities).package.json:61 - SASS variable overrides require the sass preprocessor and in the loader plugin; use
vuetify({ styles: { configFile: 'src/styles/settings.scss' } }).@use 'vuetify/settings' with (...) - v4 styles ship in cascade layers (,
vuetify-core,vuetify-components,vuetify-overrides,vuetify-utilities); unlayered user CSS now always wins over Vuetify.vuetify-final - Entry points, variables, layers, Tailwind interop, legacy grid restore: references/styling.md
- 是包含所有内容的预编译 CSS;模块化入口包括
import 'vuetify/styles'(必须最先引入)、vuetify/styles/core和vuetify/styles/colors(vuetify/styles/utilities)。package.json:61 - 覆盖 SASS 变量需要使用 sass 预处理器,并在 loader plugin 中配置 ;使用
vuetify({ styles: { configFile: 'src/styles/settings.scss' } })。@use 'vuetify/settings' with (...) - v4 样式使用 cascade layers(、
vuetify-core、vuetify-components、vuetify-overrides、vuetify-utilities);未分层的用户 CSS 现在始终优先于 Vuetify。vuetify-final - 入口点、变量、图层、Tailwind 互操作和 legacy grid 恢复:references/styling.md
Migrating from v3
从 v3 迁移
v4 is a breaking MD3 release. Highest-impact changes:
- Grid uses CSS ;
gapis nowdense,density="compact"/align/justify/orderprops replaced by utility classes. VRow gains aalign-selfprop (gap).lib/components/VGrid/VRow.js:154 - Typography variants renamed: -
h1->h3,display-*-h4->h6,headline-*/subtitle-1->body-1,body-large->caption,body-small/button->subtitle-2.label-large - Elevation reduced from levels 0-24 to 0-5 ().
lib/styles/settings/_elevations.scss:6 - /
VSelect/VComboboxslotVAutocompleterenamed toitem;internalItemis now an alias foritem.internalItem.raw - slot values (
VForm,isValid, ...) are unwrapped, no longer refs.errors - Defaults merging skips ; use
undefinedto override a global default.null
Full change list with compat snippets: references/migration-v4.md
v4 是采用 MD3 的破坏性升级。影响最大的变更包括:
- Grid 使用 CSS ;
gap现在改为dense,density="compact"/align/justify/orderprops 被工具类取代。VRow 新增了align-selfprop(gap)。lib/components/VGrid/VRow.js:154 - Typography variants 已重命名:-
h1->h3,display-*-h4->h6,headline-*/subtitle-1->body-1,body-large->caption,body-small/button->subtitle-2。label-large - Elevation 从 0-24 级减少为 0-5 级()。
lib/styles/settings/_elevations.scss:6 - /
VSelect/VCombobox的VAutocompleteslot 已重命名为item;internalItem现在是item的别名。internalItem.raw - 的 slot 值(
VForm、isValid等)已解包,不再是 refs。errors - Defaults 合并时会跳过 ;如需覆盖全局默认值,请使用
undefined。null
包含完整变更列表和兼容代码片段:references/migration-v4.md
Common pitfalls
常见问题
- Missing icon font: components render blank icons until CSS (or an SVG set) is installed.
@mdi/font - Missing Roboto font: text renders with fallback font ().
README.md:159 - Styles broken after adding custom CSS: check layer order; place overrides inside or declare your layer order explicitly.
@layer vuetify-overrides - uses
VNumberInputinternally; for arbitrary-precision decimals usetoFixed()with decimal.js (v-text-field, https://vuetifyjs.com/components/number-inputs/).lib/components/VNumberInput/VNumberInput.js:81 - Do not use inside SASS files; it resolves to precompiled CSS. Use
vuetify/stylesorvuetify(https://vuetifyjs.com/features/sass-variables/).vuetify/settings
- 缺少图标字体:安装 CSS 或 SVG 图标集之前,组件中的图标会显示为空白。
@mdi/font - 缺少 Roboto 字体:文本会使用回退字体渲染()。
README.md:159 - 添加自定义 CSS 后样式损坏:检查图层顺序;将覆盖样式放在 中,或显式声明图层顺序。
@layer vuetify-overrides - 内部使用
VNumberInput;如需任意精度的小数,请使用搭配 decimal.js 的toFixed()(v-text-field,https://vuetifyjs.com/components/number-inputs/)。lib/components/VNumberInput/VNumberInput.js:81 - 不要在 SASS 文件中使用 ;它会解析为预编译 CSS。请使用
vuetify/styles或vuetify(https://vuetifyjs.com/features/sass-variables/)。vuetify/settings
References
参考
- references/exports.md — entry points, component inventory, directives, iconsets, locale
- references/configuration.md — every option with examples
createVuetify - references/composables.md — public composables API
- references/styling.md — CSS and SASS entry points, variables, layers
- references/migration-v4.md — v3 to v4 breaking changes and compat snippets
Official documentation: https://vuetifyjs.com. Release notes by URL: https://vuetifyjs.com/getting-started/release-notes/.
- references/exports.md——入口点、组件清单、directives、图标集和 locale
- references/configuration.md——所有 选项及示例
createVuetify - references/composables.md——公共 composables API
- references/styling.md——CSS 和 SASS 入口点、变量与图层
- references/migration-v4.md——v3 到 v4 的破坏性变更和兼容代码片段
官方文档:https://vuetifyjs.com。Release notes(按 URL 访问):https://vuetifyjs.com/getting-started/release-notes/。