【Vue】vue整合element

上一篇: vue项目的创建

https://blog.csdn.net/m0_67930426/article/details/134816155

目录

整合过程

使用:


整合过程

项目创建完之后,使用编译器打开项目

在控制器里输入如下命令

npm install element-ui

如图表示安装完毕

然后在main.js配置element组件

复制代码
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
复制代码
Vue.use(ElementUI)

element官网

https://element.eleme.cn/#/zh-CN/component/menu

如果对element组件不太熟悉,可以进入官网,查找想使用的组件

使用:

例如我在官网找了一段侧栏的代码

bash 复制代码
 <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b">
    <el-submenu index="1">
      <template slot="title">
        <i class="el-icon-location"></i>
        <span>导航一</span>
      </template>
      <el-menu-item-group>
        <template slot="title">分组一</template>
        <el-menu-item index="1-1">选项1</el-menu-item>
        <el-menu-item index="1-2">选项2</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="分组2">
        <el-menu-item index="1-3">选项3</el-menu-item>
      </el-menu-item-group>
      <el-submenu index="1-4">
        <template slot="title">选项4</template>
        <el-menu-item index="1-4-1">选项1</el-menu-item>
      </el-submenu>
    </el-submenu>
    <el-menu-item index="2">
      <i class="el-icon-menu"></i>
      <span slot="title">导航二</span>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <i class="el-icon-document"></i>
      <span slot="title">导航三</span>
    </el-menu-item>
    <el-menu-item index="4">
      <i class="el-icon-setting"></i>
      <span slot="title">导航四</span>
    </el-menu-item>
  </el-menu>

在view中创建一个文件

将上述代码放到该文件中

bash 复制代码
<template>
  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b">
    <el-submenu index="1">
      <template slot="title">
        <i class="el-icon-location"></i>
        <span>导航一</span>
      </template>
      <el-menu-item-group>
        <template slot="title">分组一</template>
        <el-menu-item index="1-1">选项1</el-menu-item>
        <el-menu-item index="1-2">选项2</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="分组2">
        <el-menu-item index="1-3">选项3</el-menu-item>
      </el-menu-item-group>
      <el-submenu index="1-4">
        <template slot="title">选项4</template>
        <el-menu-item index="1-4-1">选项1</el-menu-item>
      </el-submenu>
    </el-submenu>
    <el-menu-item index="2">
      <i class="el-icon-menu"></i>
      <span slot="title">导航二</span>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <i class="el-icon-document"></i>
      <span slot="title">导航三</span>
    </el-menu-item>
    <el-menu-item index="4">
      <i class="el-icon-setting"></i>
      <span slot="title">导航四</span>
    </el-menu-item>
  </el-menu>

</template>
<script>
export default {
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  }
}
</script>
<script setup>
</script>
<script setup>
</script>

然后配置该文件的路由

然后运行项目 (npm run serve )

相关推荐
伊可历普斯3 分钟前
前端数据校验太难?一个 Zod 就够了
前端·javascript
陈林梓3 分钟前
Axios 二次封装指南 & 跨系统复用建议
前端
ZoeLandia4 分钟前
基于 qiankun 的应用间页面跳转
前端·前端框架
前端 贾公子10 分钟前
unplugin-icons == elementPlus自动引入icon
前端·javascript·vue.js
YFLICKERH12 分钟前
【Python-Web后端开发框架】Flask | Django | FastAPI | Tornado 选型与 使用 | 特性
前端·python·flask
光影少年21 分钟前
说说模块化规范?CommonJS和ES Module的区别?
前端·javascript·elasticsearch
telllong1 小时前
C++20 Modules:从入门到真香
java·前端·c++20
叫我一声阿雷吧1 小时前
JS 入门通关手册(21):原型链:JS 继承的底层原理
开发语言·javascript·前端面试·原型链·js继承·js进阶·js面向对象
是Yu欸1 小时前
LangGraph 智能体状态管理与决策
java·javascript·数据库