表Vuejs中的菜单

发布于 2025-02-07 23:41:52 字数 2725 浏览 2 评论 0原文

因此,我正在使用Element Plus Table,我想组合元素加上表和元素以及菜单IE

我希望在桌子标题中使用这种下拉菜单。

<el-menu
    :default-active="activeIndex"
    class="el-menu-demo"
    mode="horizontal"
    @select="handleSelect"
  >
    <el-sub-menu index="1">
      <template #title>Workspace</template>
      <el-menu-item index="2-1">item one</el-menu-item>
      <el-menu-item index="2-2">item two</el-menu-item>
      <el-menu-item index="2-3">item three</el-menu-item>
      <el-sub-menu index="2-4">
        <template #title>item four</template>
        <el-menu-item index="2-4-1">item one</el-menu-item>
        <el-menu-item index="2-4-2">item two</el-menu-item>
        <el-menu-item index="2-4-3">item three</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
  </el-menu>

我的表是

<el-table :data="filtered"  border style="width: 100%" height="500" @selection-change="handleSelectionChange" @header-click="contextmenu">
  <el-table-column type="selection" width="55"/>
  <el-table-column  fixed align="center" v-for="col in columns" :prop="col.field" :label="col.field" :key="col.field"/>

“在此处输入图像描述”

但是我在结合这两个标签时面临困难。 我发现元素加上表有一个事件@header-click =“”存储标题值等。

我是Vue的新手,因此对任何建议都表示赞赏。

答案 @ivogelov是正确的。这是我的最终代码,我已经进行了几个更改,因为现在不推荐使用插槽。

<el-table :data="filtered"  border style="width: 100%" height="500" @selection-change="handleSelectionChange" @header-click="contextmenu" >
  <el-table-column type="selection" width="55"/>
  <el-table-column  fixed align="center"  v-for="col in columns" :prop="col.field" :label="col.field" :key="col.field">
  <template #header >
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect">
          <el-sub-menu index="1">
            <template #title>{{col.field}}</template>
            <el-menu-item index="2-1">Source</el-menu-item>
            <el-menu-item index="2-2">Target</el-menu-item>
            </el-sub-menu>
        </el-menu>
      </template>  
      </el-table-column>
      <el-table>

So, I am working with element plus table, and I want to combine the element plus table and element plus menu i.e.
enter image description here

I want this kind of drop down menu in my table headers.

<el-menu
    :default-active="activeIndex"
    class="el-menu-demo"
    mode="horizontal"
    @select="handleSelect"
  >
    <el-sub-menu index="1">
      <template #title>Workspace</template>
      <el-menu-item index="2-1">item one</el-menu-item>
      <el-menu-item index="2-2">item two</el-menu-item>
      <el-menu-item index="2-3">item three</el-menu-item>
      <el-sub-menu index="2-4">
        <template #title>item four</template>
        <el-menu-item index="2-4-1">item one</el-menu-item>
        <el-menu-item index="2-4-2">item two</el-menu-item>
        <el-menu-item index="2-4-3">item three</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
  </el-menu>

My table is

<el-table :data="filtered"  border style="width: 100%" height="500" @selection-change="handleSelectionChange" @header-click="contextmenu">
  <el-table-column type="selection" width="55"/>
  <el-table-column  fixed align="center" v-for="col in columns" :prop="col.field" :label="col.field" :key="col.field"/>

enter image description here

But I am facing a hard time in combining these two tags.
I found out that element plus table has an event @header-click="" that stores the header values etc, but I don't know how I can use that to call the menu tag of element plus.

I am new to vue so any suggestions are appreciated.

ANSWER
@IVOGELOV is correct. Here is my final code, I have made a couple of changes since slot-scope is now deprecated.

<el-table :data="filtered"  border style="width: 100%" height="500" @selection-change="handleSelectionChange" @header-click="contextmenu" >
  <el-table-column type="selection" width="55"/>
  <el-table-column  fixed align="center"  v-for="col in columns" :prop="col.field" :label="col.field" :key="col.field">
  <template #header >
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect">
          <el-sub-menu index="1">
            <template #title>{{col.field}}</template>
            <el-menu-item index="2-1">Source</el-menu-item>
            <el-menu-item index="2-2">Target</el-menu-item>
            </el-sub-menu>
        </el-menu>
      </template>  
      </el-table-column>
      <el-table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他是夢罘是命 2025-02-14 23:41:52

您可以在列中使用标题插槽或render-header函数,如此中文文章“ nofollow noreferrer”>这个github问题

<template>
  <el-table :data="tableData"style="width: 100%">
    <el-table-column prop="name">
      <template slot="header" slot-scope="scope">
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
        >
          <el-sub-menu index="1">
            <template #title>Workspace</template>
            <el-menu-item index="2-1">item one</el-menu-item>
            <el-menu-item index="2-2">item two</el-menu-item>
            <el-menu-item index="2-3">item three</el-menu-item>
            <el-sub-menu index="2-4">
              <template #title>item four</template>
              <el-menu-item index="2-4-1">item one</el-menu-item>
              <el-menu-item index="2-4-2">item two</el-menu-item>
              <el-menu-item index="2-4-3">item three</el-menu-item>
            </el-sub-menu>
          </el-sub-menu>
        </el-menu>
      </template>
    </el-table-column>
  </el-table>
</template>

You can use the header slot in columns or the render-header function as explained in this Chinese article or this Github issue.

<template>
  <el-table :data="tableData"style="width: 100%">
    <el-table-column prop="name">
      <template slot="header" slot-scope="scope">
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
        >
          <el-sub-menu index="1">
            <template #title>Workspace</template>
            <el-menu-item index="2-1">item one</el-menu-item>
            <el-menu-item index="2-2">item two</el-menu-item>
            <el-menu-item index="2-3">item three</el-menu-item>
            <el-sub-menu index="2-4">
              <template #title>item four</template>
              <el-menu-item index="2-4-1">item one</el-menu-item>
              <el-menu-item index="2-4-2">item two</el-menu-item>
              <el-menu-item index="2-4-3">item three</el-menu-item>
            </el-sub-menu>
          </el-sub-menu>
        </el-menu>
      </template>
    </el-table-column>
  </el-table>
</template>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文