element-plus 完成下拉切换功能

项目场景:

element-plus element-plus 完成下拉切换功能,选用了popover 组件去进行样式修改,本来大概是要实现下面这样的样式效果,没想到调整的时候,这个选择的高亮模块总是超出。

实现效果:



解决方案:

其实是选用了错误的组件去实现这个功能,对于这种需求我们应该用DropDown(下拉菜单去实现),在这里特此记录,希望以后实现功能的时候,不要再犯错

错误代码(用于引以为戒):

<template>
  <el-popover
    placement="bottom"
    :width="160"
    trigger="hover"
    popper-class="select-down"
  >
    <template #reference>
      <img src="@/assets/icon/i18n.svg" class="icon" />
    </template>
    <template #default>
      <div style="display: flex; flex-direction: column; padding: 0 0">
        <div class="lang">中文</div>
        <div class="lang">英文</div>
      </div>
    </template>
  </el-popover>

  <!-- <I18n /> -->
</template>

<style lang="scss">
.select-down {
  padding: 10px 0 !important;
}

.icon {
  width: 30px;
  height: 30px;
}

.lang {
  width: 100%;
  height: 26px;
  line-height: 26px;
  padding-left: 20px;
}
.lang:hover {
  background-color: #ecf5ff;
  color: #409eff;
}
</style>

正确的实现:

<template>
  <el-dropdown :hide-on-click="false">
    <img src="@/assets/icon/i18n.svg" class="icon" />
    <template #dropdown>
      <el-dropdown-menu>
        <template v-for="(item, index) in localeList" :key="index">
          <el-dropdown-item @click="toggleLocal(item.event)">{{
            item.text
          }}</el-dropdown-item>
        </template>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>
<script setup lang="ts">
import { localeList } from "@/settings/localeSetting";

async function toggleLocal(lang: LocaleType) {
 
}
</script>
<style lang="scss">
.icon {
  width: 30px;
  height: 30px;
}

.el-tooltip__trigger:focus {
  outline: none !important;
}
</style>

效果如下:

本来早就应该发的,可是上班真的好累,屯了四五篇,这次统一发了吧,代码有问题记得下方留言。

相关推荐

  1. Element-Plus Dropdown 菜单样式修改

    2024-03-18 12:44:02       39 阅读
  2. 使用 Vue.js 和 Element Plus 实现自动完成搜索功能

    2024-03-18 12:44:02       28 阅读
  3. awtk界面实现功能

    2024-03-18 12:44:02       40 阅读
  4. element-ui select 框做成加载更多

    2024-03-18 12:44:02       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-18 12:44:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-18 12:44:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-18 12:44:02       87 阅读
  4. Python语言-面向对象

    2024-03-18 12:44:02       96 阅读

热门阅读

  1. RabbitMq——direct交换器和fanout交换器 扇形交换器

    2024-03-18 12:44:02       41 阅读
  2. uni-app多次触发事件,防止重复点击

    2024-03-18 12:44:02       41 阅读
  3. Sklearn K-均值算法

    2024-03-18 12:44:02       39 阅读
  4. Springboot中常用工具类

    2024-03-18 12:44:02       33 阅读
  5. OpenResty使用Lua大全(七)OpenResty使用全局缓存

    2024-03-18 12:44:02       48 阅读
  6. 软件测试行业的现状和前景?

    2024-03-18 12:44:02       46 阅读
  7. 比特币,区块链及相关概念简介(四)

    2024-03-18 12:44:02       52 阅读
  8. 开源项目_搭建对象存储服务MinIO

    2024-03-18 12:44:02       39 阅读
  9. 设计模式之建造者模式

    2024-03-18 12:44:02       42 阅读