Element-UI是饿了么前端团队推出的一款基于Vue.js 2.0 的桌面端UI框架,手机端有对应框架是 Mint UI 。
<font size="5"> <strong>1. 什么是vue-cli</strong> </font> vue-cli 是vue官方提供的脚手架工具。脚手架工具简单讲就是自动将项目需要的环境、依赖等信息都配置好。 <br/> <font size="5"> <strong>2. 安装vue-cli</strong> </font>
//安装
npm install -g @vue/cli
//卸载
npm uninstall vue-cli -g
安装完成后查看版本信息
vue --version
安装成功如下图所示
<br/> <font size="5"> <strong>3. 创建vue项目</strong> </font>
// 'project_name' 为自定义项目名称
vue create project_name
常用的选择
(*) Babel // 是否使用babel做转义
( ) TypeScript // 是否使用class风格的组件语法
( ) Progressive Web App (PWA) Support // 支持PWA
(*) Router // 安装使用路由Router
(*) Vuex // 安装使用Vuex状态管理,简单项目不建议使用安装
(*) CSS Pre-processors // 选择CSS 预处理类型
>(*) Linter / Formatter // 选择Linter / Formatter规范类型
( ) Unit Testing // 选择Unit测试方式
( ) E2E Testing // 选择E2E测试方式
Vue CLI v5.0.1
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
? Choose a version of Vue.js that you want to start the project with 2.x
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
? Pick a linter / formatter config: Basic
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In package.json
? Save this as a preset for future projects? (y/N) n
<br/> <font size="5"> <strong>4. 安装Element-UI</strong> </font>
npm install element-ui --save
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
Vue.config.productionTip = false;
// 引入element-ui
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI); //一定记得要使用
new Vue({
router,
store,
render: h => h(App)
}).$mount("#app");
<br/> <font size="5"> <strong>5. 使用Element-UI组件</strong> </font>
可以前往Element-UI组件库查看更多操作
<template>
<div class="about">
<h1>This is an element-ui page</h1>
<el-button @click="show = !show">Click Me</el-button>
<div style="display: flex; margin-top: 20px; height: 100px;">
<transition name="el-fade-in-linear">
<div v-show="show" class="transition-box">.el-fade-in-linear</div>
</transition>
<transition name="el-fade-in">
<div v-show="show" class="transition-box">.el-fade-in</div>
</transition>
</div>
</div>
</template>
<script>
export default {
data: () => ({
show: true
})
}
</script>
<style>
.transition-box {
margin-bottom: 10px;
width: 200px;
height: 100px;
border-radius: 4px;
background-color: #409EFF;
text-align: center;
color: #fff;
padding: 40px 20px;
box-sizing: border-box;
margin-right: 20px;
}
</style>
<font color="red">注:如果运行出现<kbd>Mixed spaces and tabs no-mixed-spaces-and-tabs</kbd>报错</font>
"no-mixed-spaces-and-tabs":0