实战 | Vue + Element UI 页面创建

1,698 阅读1分钟

本篇将会着重讲解关于Vue和Element UI 相关的内容

思维导图

![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/ef706d6f238c4e6fbde16d69ad91580a?from=pc)

网页版Vue Cli 基本使用

这里使用Vue Cli 进行基本的使用

安装

npm install -g @vue/cli

安装的界面如下

PS C:UsersAdministratorDesktop> npm install -g @vue/clinpm WARN deprecated @hapi/joi@15.1.1: joi is leaving the @hapi organization and moving back to 'joi' (https://github.com/sideway/joi/issues/2411)npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintainednpm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintainednpm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintainednpm WARN deprecated @hapi/address@2.1.4: This version has been deprecated and is no longer supported or maintainednpm WARN deprecated har-validator@5.1.5: this library is no longer supported[..................] / loadDep:sha.js: sill resolveWithNewModule apollo-env@0.6.5 checking installable status
![实战 | Vue + Element UI 页面创建](https://p3-tt.byteimg.com/origin/pgc-image/700db19e75b24a2fad5b11629d6ba6fa?from=pc)

检查版本是否正确

vue -V
![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/b7755ee87e9741b2abbd9c8cac101681?from=pc)

这里安装完成。

打开网页版vue-cli

进入Vue页面

![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/f18e83a7dc8241b9b7076b6216ff9c3c?from=pc)

选择目录

![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/368743c8ab6447d4a4cfaf9e919091c1?from=pc)

选择预设

![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/ce9568d96f78472d99b0e38400b6c8a9?from=pc)

选择功能

![实战 | Vue + Element UI 页面创建](https://p1-tt.byteimg.com/origin/pgc-image/abddd449bf7c472cbe66275fd8298200?from=pc)

创建项目

![实战 | Vue + Element UI 页面创建](https://p3-tt.byteimg.com/origin/pgc-image/943961fa2d414d48ad5d31f77cca7cac?from=pc)
![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/9331124484764eb0bf2ee66aef9d1306?from=pc)

项目创建完成

![实战 | Vue + Element UI 页面创建](https://p6-tt.byteimg.com/origin/pgc-image/4f5cf9fcd1f4413d8f2d6feda1763131?from=pc)

启动程序并运行

![实战 | Vue + Element UI 页面创建](https://p3-tt.byteimg.com/origin/pgc-image/5fce3cdd81904dc5acabeff92042c2ed?from=pc)
![实战 | Vue + Element UI 页面创建](https://p3-tt.byteimg.com/origin/pgc-image/c5b9f8397d6647bfb85457759601fc38?from=pc)

安装Element UI

npm i element-ui -S

这里就可以看到已经安装完成。

体验Element UI

main.js 如下

import Vue from 'vue'import App from './App.vue'import router from './router'import store from './store'import Element from 'element-ui'import 'element-ui/lib/theme-chalk/index.css'Vue.use(Element)Vue.config.productionTip = falsenew Vue({  router,  store,  render: h => h(App)}).$mount('#app')

about.vue 如下

<template>  <div class="about">    <i class="el-icon-edit"></i>    <i class="el-icon-share"></i>    <i class="el-icon-delete"></i>    <el-button type="primary" icon="el-icon-search">搜索</el-button>  </div></template>

router.js 如下

import Vue from 'vue'import VueRouter from 'vue-router'import Home from '../views/Home.vue'Vue.use(VueRouter)  const routes = [  {    path: '/',    name: 'Home',    component: Home  },  {    path: '/login',    name: 'Login',    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')  },  {    path: '/about',    name: 'About',    // route level code-splitting    // this generates a separate chunk (about.[hash].js) for this route    // which is lazy-loaded when the route is visited.    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')  }]const router = new VueRouter({  mode: 'history',  base: process.env.BASE_URL,  routes})export default router

文件目录如下

![实战 | Vue + Element UI 页面创建](https://p3-tt.byteimg.com/origin/pgc-image/9bd7958d3bda4acd98893b66636c5160?from=pc)

访问效果如下

![实战 | Vue + Element UI 页面创建](https://p1-tt.byteimg.com/origin/pgc-image/a0fc7c5acc56472886d89487dad94619?from=pc)

总结

以上简单的完成了一个Element UI 的页面的创建