el-table 设置固定宽度弹框

java 复制代码
  <template #default="scope">
          <el-tooltip effect="dark" placement="top">
            <template #content>
              <div class="set-popper">{{scope.row.content}}</div>
            </template>
            <div class="set-content">{{ scope.row.content }}</div>
          </el-tooltip>
        </template>
<style lang="scss" scoped>
.set-popper {
  max-width: 500px;
}
.set-content {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>

案例:

复制代码
<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            size="mini"
            @click="handleAdd"
            v-hasPermi="['business:servermsg:add']"
        >
          <el-icon>
            <plus/>
          </el-icon>
          新增
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="servermsgList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" width="60" :show-overflow-tooltip="true">
        <template v-slot="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="ID" align="center" prop="id"/>-->
      <el-table-column label="文案标题" align="center" prop="text"/>
      <el-table-column label="内容介绍" :align="center" prop="content">
        <template #default="scope">
          <el-tooltip effect="dark" placement="top">
            <template #content>
              <div class="set-popper">{{scope.row.content}}</div>
            </template>
            <div class="set-content">{{ scope.row.content }}</div>
          </el-tooltip>
        </template>

      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
          >
            <el-icon>
              <edit/>
            </el-icon>
            修改
          </el-button>
          <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
          >
            <el-icon>
              <delete/>
            </el-icon>
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改服务器管理对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">

        <el-form-item  label-position="right" label="文案标题" prop="text">
          <el-input    maxlength="200" show-word-limit v-model="form.text" placeholder="请输入文案标题"/>
        </el-form-item>
        <el-form-item  label="内容介绍" prop="content" label-width="100" >
          <editor v-model="form.content"  show-word-limit  :min-height="192"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style lang="scss" scoped>
.set-popper {
  max-width: 500px;
}
.set-content {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>

<script>
import {getGiraffeManorInstro, addGiraffeManorInstro, listGiraffeManorInstro, delGiraffeManorInstro, updateGiraffeManorInstro} from "@/api/business/giraffemanorInstro";
import Pagination from '@/components/Pagination'
export default {
  name: "Servermsg",
  data() {
    return {
      isDisable:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务器管理表格数据
      servermsgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // serverId: [{ required: true, message: "服务器Id不能为空", trigger: "blur" }],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询服务器管理列表 */
    getList() {
      this.loading = true;
      listGiraffeManorInstro(this.queryParams).then(response => {
        this.servermsgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加宣传配置";
      this.isDisable=false;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      debugger
      const id = row.id || this.ids
      getGiraffeManorInstro(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.isDisable=true;
        this.title = "修改宣传配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          debugger
          if (this.form.id != null) {

            updateGiraffeManorInstro(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            debugger
            addGiraffeManorInstro(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除标题为"' + row.text + '"的数据项?').then(function () {
        return delGiraffeManorInstro(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    }
  }
};
</script>
相关推荐
是一碗螺丝粉8 小时前
React Native 运行时深度解析
前端·react native·react.js
Jing_Rainbow8 小时前
【前端三剑客-9 /Lesson17(2025-11-01)】CSS 盒子模型详解:从标准盒模型到怪异(IE)盒模型📦
前端·css·前端框架
爱泡脚的鸡腿9 小时前
uni-app D6 实战(小兔鲜)
前端·vue.js
青年优品前端团队9 小时前
🚀 不仅是工具库,更是国内前端开发的“瑞士军刀” —— @qnvip/core
前端
骑自行车的码农9 小时前
🍂 React DOM树的构建原理和算法
javascript·算法·react.js
北极糊的狐9 小时前
Vue3 中父子组件传参是组件通信的核心场景,需遵循「父传子靠 Props,子传父靠自定义事件」的原则,以下是资料总结
前端·javascript·vue.js
看到我请叫我铁锤9 小时前
vue3中THINGJS初始化步骤
前端·javascript·vue.js·3d
q***25219 小时前
SpringMVC 请求参数接收
前端·javascript·算法
q***33379 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
烛阴10 小时前
从`new()`到`.DoSomething()`:一篇讲透C#方法与构造函数的终极指南
前端·c#