- 环境
- vue 2.6.11
- vue/cli 3.11.0
- elementui vue脚手架自动安装2.4.5
- 新建项目
- vue create elementui
- 引入element-ui
- vue add element
- 使用
-
安装完成后不用手动去引入elementui,脚手架自动引入了elementui.
-
打开main.js,看下图
-
再打开App.vue,看下图
-
脚手架自动引入了elementui,并且在App.vue中做了一个例子.
- 运行项目就可以看到首页中多了一个elementui样式的按钮.
-
- 手动使用elementui
- src/router/index.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: '/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
- App.vue代码如下(紫色为有改动部分)
<template> <div id="app"> <router-link to="/">Home</router-link> <router-link to="/About">About</router-link> <router-view></router-view> </div> </template> <script> import Home from './views/Home' import About from './views/About' export default { name: 'app', components: { Home, About } } </script>
- Home.vue代码如下(紫色为有改动部分)
<template> <div class="home"> <el-row> <el-button>默认按钮</el-button> <el-button type="primary">主要按钮</el-button> <el-button type="success">成功按钮</el-button> <el-button type="info">信息按钮</el-button> <el-button type="warning">警告按钮</el-button> <el-button type="danger">危险按钮</el-button> </el-row> </div> </template> <script> // @ is an alias to /src export default { name: "Home", components: { } }; </script>
- 运行项目查看结果
- src/router/index.js中路由配置如下(项目创建完成时就这样,没有改动)