赞
踩
网站快速成型工具
Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库
这篇文章的作用就是让自学的小伙伴们,少费点时间,把时间用在学习新的知识上。为什么这么说呢?在使用饿了么UI库时,有不少的坑的。
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"/>
<!-- 引入vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <!-- 引入样式 --> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"/> <!-- 引入vue 第二个是引入的node_modules中的vue --> <script src="https://unpkg.com/vue/dist/vue.js"></script> <!-- <script src="./element-ui-test/node_modules/vue/dist/vue.js"></script> --> <!-- 引入组件库 --> <script src="https://unpkg.com/element-ui/lib/index.js"></script> </head> <body> <div id="app"> <el-rate v-model="value" show-text> </el-rate> <br><br> <el-row> <el-button round>圆角按钮</el-button> <el-button type="primary" round>主要按钮</el-button> <el-button type="success" round>成功按钮</el-button> <el-button type="info" round>信息按钮</el-button> <el-button type="warning" round>警告按钮</el-button> <el-button type="danger" round>危险按钮</el-button> </el-row> <br><br> <el-row> <el-button icon="el-icon-search" circle></el-button> <el-button type="primary" icon="el-icon-edit" circle></el-button> <el-button type="success" icon="el-icon-check" circle></el-button> <el-button type="info" icon="el-icon-message" circle></el-button> <el-button type="warning" icon="el-icon-star-off" circle></el-button> <el-button type="danger" icon="el-icon-delete" circle></el-button> </el-row> </div> </body> <script> const vm = new Vue({ el: '#app', data: { value: null, }, }) </script> </html>
vue create [项目名称]
就是先要初始化一个vue项目。npm i element-ui -S
main.js
文件中加入以下代码(其实就两个import导入)import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
Vue.use(ElementUI);
new Vue({
el: '#app',
render: h => h(App)
});
babel-plugin-component
。安装命令是:npm install babel-plugin-component -D
main.js
中加入下面代码(小伙伴们自己看着改哈)import Vue from 'vue'; import { Button, Select } from 'element-ui'; // 样式文件不可以少 import 'element-ui/lib/theme-chalk/index.css'; import App from './App.vue'; Vue.component(Button.name, Button); Vue.component(Select.name, Select); /* 或写为 * Vue.use(Button) * Vue.use(Select) */ new Vue({ el: '#app', render: h => h(App) });
App.vue
组件中使用就可以了。我复制个代码,以便于好理解main.js
文件中import { Button, Select, Carousel, CarouselItem } from 'element-ui';
中引入Carousel, CarouselItem
这两个组件。并且在下面加上Vue.use(Carousel); Vue.use(CarouselItem);
这两行代码才可以实现下面展示的效果<template> <div id="app"> <el-carousel :interval="4000" type="card" height="200px"> <el-carousel-item v-for="item in 6" :key="item"> <h3 class="medium">{{ item }}</h3> </el-carousel-item> </el-carousel> </div> </template> <script> export default { name: "App" </script> <style lang="less"> .el-carousel__item h3 { color: #475669; font-size: 14px; opacity: 0.75; line-height: 200px; margin: 0; } .el-carousel__item:nth-child(2n) { background-color: #99a9bf; } .el-carousel__item:nth-child(2n + 1) { background-color: #d3dce6; } </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。