概述

作为一个组件框架,Vuetify将持续水平成长。但根据您的项目,可能只需要一个小的安装包体积。所以单组件(原文以为区别于套餐的点菜)系统使您能够选择要导入的组件, 大幅度降低 您的构建体积。如果您已经安装了“单点菜单”模版,则可以跳到指南

组件导入

Tree shaking only works with webpack 4 in production mode

transform-imports包不需要使用点菜组件,但是简化了导入他们的过程,所以非常值得推荐。它允许您在导入组件时使用更简洁的语法。

The options object that you pass as the second argument to Vue.use can also include both a directives and a transitions property.

如果您没有使用transform-imports包,则需要像这样导入每个组件:

所需要的样式

为了获得所需要的样式,我们需要将它们导入到stylus中。而为了webpack来处理这个,你需要从npm安装stylusstylus-loader

现在您需要从应用程序的入口点开始使用stylus,跟您导入Vue和Vuetify的地方一样(通常是main.js或者 app.js)。请记住,在您的主App.vue中这样做会导致加载速度慢,因为当您进行更新的时候它会被重新处理。

For a more detailed explanation on how to setup your application to handle stylus, please navigate to the theme page.

vuetify-loader

Keeping track of all the components you're using can be a real chore, so we wrote a webpack loader to help you. vuetify-loader will automatically import all the vuetify components you use, where you use them. This will also make code-splitting more effective, as webpack will only load the components required for that chunk to be displayed.

Now any Vuetify component used in a template will be automatically added to an in-component import like above.

Limitations

When using the vuetify-loader, there are a few scenarios which will require manual importing of components.

Dynamic components

v-data-iterator can use any component via the content-tag prop. This component must be registered globally:

Dynamic components used with <component :is=""> can be registered locally:

Functional components

Functional components are inlined at runtime by vue, and cannot have a components property in their options. Any vuetify components used in a custom functional component must either be registered globally (recommended), or locally wherever the custom component is used.

Edit this page | language on Github
Vuetify 3 is now available!The latest version of Vuetify is now available!
Learn about Vuetify 3's new features and functionality for modern Vue applications
Start exploringExplore