ant-design-vue/docs/vue/getting-started.en-US.md

144 lines
4.3 KiB
Markdown
Raw Normal View History

2018-04-09 22:49:58 +08:00
# Getting Started
2018-09-14 10:04:08 +08:00
Ant Design Vue is dedicated to providing a **good development experience** for programmers. Make sure that you had installed [Node.js](https://nodejs.org/)(> v8.9) correctly.
2018-04-09 22:49:58 +08:00
2018-04-10 12:08:41 +08:00
> Before delving into Ant Design Vue, a good knowledge base of [Vue](https://cn.vuejs.org/) and [JavaScript ES2015](http://babeljs.io/docs/learn-es2015/) is needed.
2018-04-09 22:49:58 +08:00
2019-01-02 16:12:48 +08:00
## Use vue-cli@3
2019-09-28 20:45:07 +08:00
2019-01-02 16:12:48 +08:00
We provide an [Ant Design Vue](https://github.com/vueComponent/vue-cli-plugin-ant-design) plugin for vue-cli@3, which you can use to quickly build an Ant Design Vue-based project.
2018-04-09 22:49:58 +08:00
## Playground
The following CodeSandbox demo is the simplest use case, and it's also a good habit to fork this demo to provide a re-producible demo while reporting a bug.
2018-04-10 12:08:41 +08:00
- [![Vue Antd Template](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/2wpk21kzvr)
2018-04-09 22:49:58 +08:00
## Import ant-design-vue
2018-04-09 22:49:58 +08:00
### 1. Installation
2018-04-10 12:08:41 +08:00
[vue-cli](https://github.com/vuejs/vue-cli)
2018-04-09 22:49:58 +08:00
```bash
2018-09-14 10:04:08 +08:00
$ npm install -g @vue/cli
# OR
$ yarn global add @vue/cli
2018-04-09 22:49:58 +08:00
```
### 2. Create a New Project
A new project can be created using CLI tools.
```bash
$ vue create antd-demo
2018-04-09 22:49:58 +08:00
```
2018-09-14 10:04:08 +08:00
And, setup your vue project configuration.
2018-04-09 22:49:58 +08:00
### 3. Use antd's Components
2018-04-10 12:08:41 +08:00
```bash
$ npm i --save ant-design-vue
2018-04-09 22:49:58 +08:00
```
2019-09-28 20:45:07 +08:00
2018-04-20 18:24:52 +08:00
**Fully import**
2019-09-28 20:45:07 +08:00
2018-04-20 18:24:52 +08:00
```jsx
2019-09-28 20:45:07 +08:00
import Vue from 'vue';
import Antd from 'ant-design-vue';
import App from './App';
import 'ant-design-vue/dist/antd.css';
Vue.config.productionTip = false;
2018-04-20 18:24:52 +08:00
2019-09-28 20:45:07 +08:00
Vue.use(Antd);
2018-04-09 22:49:58 +08:00
2018-04-20 18:24:52 +08:00
/* eslint-disable no-new */
new Vue({
el: '#app',
components: { App },
2019-09-28 20:45:07 +08:00
template: '<App/>',
});
2018-04-20 18:24:52 +08:00
```
2019-09-28 20:45:07 +08:00
2018-04-20 18:24:52 +08:00
The above imports Antd entirely. Note that CSS file needs to be imported separately.
2018-04-19 16:58:03 +08:00
**Only import the components you need**
2019-09-28 20:45:07 +08:00
2018-04-10 12:08:41 +08:00
```jsx
2019-09-28 20:45:07 +08:00
import Vue from 'vue';
import { Button, message } from 'ant-design-vue';
import App from './App';
2018-04-09 22:49:58 +08:00
2019-09-28 20:45:07 +08:00
Vue.config.productionTip = false;
2018-04-09 22:49:58 +08:00
2018-09-22 21:28:36 +08:00
/* v1.1.2 */
2019-09-28 20:45:07 +08:00
Vue.component(Button.name, Button);
Vue.component(Button.Group.name, Button.Group);
2018-09-22 21:28:36 +08:00
/* v1.1.3+ Automatically register components under Button, such as Button.Group */
2019-09-28 20:45:07 +08:00
Vue.use(Button);
2018-09-22 21:28:36 +08:00
2019-09-28 20:45:07 +08:00
Vue.prototype.$message = message;
2018-04-09 22:49:58 +08:00
2018-04-10 12:08:41 +08:00
/* eslint-disable no-new */
new Vue({
el: '#app',
components: { App },
2019-09-28 20:45:07 +08:00
template: '<App/>',
});
2018-04-09 22:49:58 +08:00
```
2018-04-10 12:08:41 +08:00
> All the components in antd are listed in the sidebar.
2018-04-09 22:49:58 +08:00
2018-04-10 12:08:41 +08:00
### 4. Component list
2018-04-09 22:49:58 +08:00
[Component list](https://github.com/vueComponent/ant-design-vue/blob/master/site/components.js)
2018-04-09 22:49:58 +08:00
## Compatibility
2018-04-10 12:08:41 +08:00
Ant Design Vue supports all the modern browsers and IE9+.
2018-04-09 22:49:58 +08:00
You need to provide [es5-shim](https://github.com/es-shims/es5-shim) and [es6-shim](https://github.com/paulmillr/es6-shim) and other polyfills for IE browsers.
If you are using babel, we strongly recommend using [babel-polyfill](https://babeljs.io/docs/usage/polyfill/) and [babel-plugin-transform-runtime](https://babeljs.io/docs/plugins/transform-runtime/) instead of those two shims.
> Please avoid using both the babel and shim methods at the same time.
## Import on Demand
If you see logs like below screenshot, you might be importing all components by writing `import { Button } from 'ant-design-vue';`. This will affect your app's network performance.
2018-04-09 22:49:58 +08:00
```
You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.
```
> ![](https://zos.alipayobjects.com/rmsportal/GHIRszVcmjccgZRakJDQ.png)
However, we can import individual components on demand:
```jsx
import Button from 'ant-design-vue/lib/button';
import 'ant-design-vue/lib/button/style'; // or ant-design-vue/lib/button/style/css for css format file
2018-04-09 22:49:58 +08:00
```
We strongly recommend using [babel-plugin-import](https://github.com/ant-design/babel-plugin-import), which can convert the following code to the 'antd/lib/xxx' way:
```jsx
import { Button } from 'ant-design-vue';
2018-04-09 22:49:58 +08:00
```
And this plugin can load styles too, read [usage](https://github.com/ant-design/babel-plugin-import#usage) for more details.
> FYI, babel-plugin-import's `style` option will importing some global reset styles, don't use it if you don't need those styles. You can import styles manually via `import 'ant-design-vue/dist/antd.css'` and override the global reset styles.
2018-04-09 22:49:58 +08:00
## Customization
2019-02-16 16:51:21 +08:00
- [Customize Theme](/docs/vue/customize-theme)
2018-04-09 22:49:58 +08:00
- [Local Iconfont](https://github.com/ant-design/antd-init/tree/master/examples/local-iconfont)
## Tips
- You can use any `npm` modules.
2018-04-10 12:08:41 +08:00
- Although Vue's official recommended template to write components, JSX is a better choice for complex components.