Vue Element按钮Dropdown实现

16 篇文章 0 订阅

前言​

欢迎大家来到我的博客,请各位看客们点赞、收藏、关注三连!

欢迎大家关注我的知识库,Java之从零开始·语雀

你的关注就是我前进的动力!

CSDN专注于问题解决的博客记录,语雀专注于知识的收集与汇总,包括分享前沿技术。

主体

需求
按钮打开有两个选项
在这里插入图片描述

<template>
  <div>
    <el-dropdown class="mainBtn">
      <el-button type="primary" size="mini"
                 @click="btnClick('')">
        {{ mainBtnLabel }}<i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <div class="dropdownBtn">
        <div class="dropButton" :style="'width:100px;height:28px'" v-for="item in buttonData"
             :key="item.label"
             @click="btnClick(item.methodName,item.type)">
          <span class="dropButtonSpan">{{ item.label }}</span>
        </div>
      </div>
      <el-dropdown-menu class="hidden">
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "ZjdsjjgCommonDropdownButton",
  props: {
    mainBtnLabel: {
      type: String,
      default: "保存并关闭"
    },
    buttonData: {
      type: Array,
      default: () => {
        return [
          {
            label: "保存",
            method: "",
          },
        ]
      }
    },
  },
  methods: {
    btnClick(methodName, type) {
      methodName = methodName || "" ? methodName : "saveAndBack";
      if (!type) {
        type = "";
      }
      this.$emit(methodName, type);
    },
  },
  computed: {},
  data() {
    return {
      showBtn: false,
    }
  }
}
</script>

<style scoped>
.mainBtn:hover .dropdownBtn {
  display: block;
}

.mainBtn .dropdownBtn {
  display: none;
}

.dropdownBtn {
  position: absolute;
  z-index: 999;
  line-height: 0;
  box-shadow: 0 1px 2px -0.8px #333333;
  background-color: #FFFFFF;
  padding-top: 5px;
  /*display: none;*/
}

.hidden {
  display: none;
}

.dropButton {
  height: 25px;
  text-align: center;
  line-height: 25px;
  cursor: pointer;
  margin-bottom: 5px;
}

.dropButton:before {
  content: '';
  display: inline-block;
  vertical-align: middle;
  height: 100%;
}

.dropButton:hover {
  background-color: #F1F4F7;
  color: #409EFF;
}

.dropButtonSpan {
  font-size: 12px;
  font-family: 'Microsoft YaHei 微软雅黑', serif;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hikktn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值