ElementUI当鼠标悬停在下拉框选项时,显示此选项的说明文字

需求

鼠标悬停在下拉框选项时,显示此选项的说明文字 。

分析

使用 @mouseover.native 触发显示消息框。 使用 @mouseout.native 关闭消息框

前端实现

消息框
<el-popover
          v-model="tooltipDisableFlag"
          placement="top-start"
          style="width: 100%;"
          trigger="focus"
          :content="popoverContent"
        />
下拉框
<el-form-item :label="$t('dict.generator')" :label-width="formLabelWidth" prop="dict_generator" :rules="rules.generator">
        <el-select v-model="temp.dict_generator" style="width:95%" class="filter-item" :placeholder="$t('dict.generatorIntro')" filterable @change="changedict">
          <el-option
            v-for="item in genOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            @mouseover.native="setMouseOver($event)"
            @mouseout.native="setMouseOut()"
          />
        </el-select>
      </el-form-item>
data()中定义,消息框中使用的变量
data() {
return {
        popoverContent: ''
        }
    }
methods 中定义 方法
	setMouseOver: function($event) {
        this.tooltipDisableFlag = true
        const selectedOption = $event.currentTarget.innerText
        for (const e in this.genOptions) {
          if (selectedOption === this.genOptions[e].name) {
            this.popoverContent = this.genOptions[e].doc
          }
        }
      },
      setMouseOut() {
        this.tooltipDisableFlag = false
      },
      // 初始化 genOptions , msgOptions
      initSelect() {
        // init the list of dict type
        fetchTypeList().then(response => {
          const tempoption = response.data.items
          for (const e in tempoption) {
            tempoption[e].label = tempoption[e].name
            tempoption[e].value = e
          }
          this.genOptions = tempoption
        })
      },
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值