element-ui : <el-table> 按钮点击操作阻止@row-click

阻止Vue表格行点击事件

描述:<el-table> 点击行时,会跳转到一个详细信息页面, 但是同时这一行也有编辑和删除按钮。

问题: 在点击按钮时,@row-click事件也被触发了,而我并不想触发 row-click 事件

解决办法: 写按钮的 @click 事件时添加 .stop

<el-button type="text" @click.stop="deleteVisible = true"><i class="el-icon-delete el-icon--right"></i></el-button>

 

参考:https://blog.youkuaiyun.com/qq_36437172/article/details/88779425

转载于:https://www.cnblogs.com/mlllily/p/10796782.html

<template> <div class="content-wrapper"> <!-- 面包屑导航 --> <el-breadcrumb separator="/"> <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item> <el-breadcrumb-item>健康体检管理</el-breadcrumb-item> </el-breadcrumb> <!-- 导出按钮 --> <el-button type="success" @click="exportData" style="margin-bottom: 20px;">导出</el-button> <!-- 筛选条件表单 --> <el-form :inline="true" class="demo-form-inline"> <el-form-item label="体检时间"> <el-date-picker v-model="filter.startDate" type="date" placeholder="开始日期"> </el-date-picker> <el-date-picker v-model="filter.endDate" type="date" placeholder="结束日期"> </el-date-picker> </el-form-item> <el-form-item label="体检地点"> <el-select v-model="filter.location" placeholder="请选择"> <el-option v-for="item in locations" :key="item" :label="item" :value="item"> </el-option> </el-select> </el-form-item> <el-form-item> <el-button type="primary" @click="search">查询</el-button> <el-button type="primary" @click="reset">重置</el-button> </el-form-item> </el-form> <!-- 体检计划列表 --> <el-table :data="plans" style="width:100%"> <el-table-column prop="name" label="体检名称" width="180"></el-table-column> <el-table-column prop="time" label="体检时间" width="180"></el-table-column> <el-table-column prop="location" label="体检地点" width="180"></el-table-column> <el-table-column prop="standard" label="体检标准" width="180"></el-table-column> <el-table-column prop="remarks" label="备注" width="180"></el-table-column> <el-table-column label="体检人员" width="180"></el-table-column> <el-table-column label="操作" width="180"> <template slot-scope="scope"> <el-button size="mini" @click="editPlan(scope.$index, scope.row)">修改</el-button> <el-button size="mini" type="danger" @click="deletePlan(scope.$index, scope.row)">删除</el-button> </template> </el-table-column> </el-table> </div> </template> <script> import axios from 'axios'; export default { data() { return { filter: { startDate: '', endDate: '', location: '', status: '' }, locations: [], plans: [] }; }, created() { this.loadLocations(); this.fetchPlans(); }, methods: { loadLocations() { axios.get('/api/health-plans/locations').then(response => { this.locations = response.data; }); }, fetchPlans() { axios.get('/api/health-plans', { params: this.filter }).then(response => { this.plans = response.data; }); }, search() { this.fetchPlans(); }, reset() { this.filter = { startDate: '', endDate: '', location: '', status: '' }; this.fetchPlans(); }, exportData() { window.open('/api/health-plans/export'); }, editPlan(index, plan) { console.log('编辑体检计划', plan); }, deletePlan(index, plan) { axios.delete(`/api/health-plans/${plan.id}`).then(() => { this.plans.splice(index, 1); this.$message.success('删除成功'); }).catch(() => { this.$message.error('删除失败'); }); } } }; </script> <style scoped> .content-wrapper { margin: 20px 40px; /* 向右下方移动 */ } .demo-form-inline { margin-bottom: 20px; } </style> 在此段代码基础上加上新增按钮按钮点击弹出后关联另外一个vue
最新发布
09-11
<template> <div> <div> <!--搜索栏--> <el-input v-model="name" placeholder="请输入菜单名称" style="width: 200px" prefix-icon="el-icon-user"></el-input> <el-button class="el-icon-search" style="margin-left: 10px" type="primary" @click="load">查询</el-button> <el-button class="el-icon-refresh" style="margin-left: 10px" type="warning" @click="reset">重置</el-button> </div> <div style="margin-top: 20px;margin-bottom:35px;"> <!-- 新增、批量删除 --> <el-button class="el-icon-plus" style="margin-right: 10px" type="success" @click="save(null)">新增</el-button> <el-button class="el-icon-close" style="margin-left: 10px" type="danger" @click="deleteByids" >批量删除</el-button> </div> <el-table :data="tableData" border stripe :header-cell-style="getRowClass" @selection-change="handleSelectionChange" row-key="id" border default-expand-all> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="id" label="id"></el-table-column> <el-table-column prop="name" label="菜单名称"></el-table-column> <el-table-column prop="path" label="菜单路径"></el-table-column> <el-table-column prop="icon" label="菜单图标"> <template v-slot:default="scope"> <i :class="scope.row.icon"></i> </template> </el-table-column> <el-table-column prop="pagePath" label="页面路径"></el-table-column> <el-table-column prop="description" label="菜单描述"></el-table-column> <el-table-column prop="sortNum" label="排序"></el-table-column> <el-table-column label="操作" width="300"> <template v-slot="scope"> <div class="action-buttons"> <!-- 添加容器方便布局 --> <el-button type="success" size="mini" class="compact-btn" @click="save(scope.row.id)" v-if="!scope.row.pid && !scope.row.path">新增子菜单</el-button> <el-button type="prima
03-29
<!--考试安排--> <template> <div> <div class="search"> <el-input placeholder="请输入标题查询" style="width: 200px" v-model="name"></el-input> <el-button type="info" plain style="margin-left: 10px" @click="load(1)">查询</el-button> <el-button type="warning" plain style="margin-left: 10px" @click="reset">重置</el-button> </div> <div class="operation"> <el-button type="primary" plain @click="handleAdd">考试安排</el-button> <el-button type="danger" plain @click="delBatch">批量删除</el-button> </div> <div class="table"> <el-table :data="tableData" stripe @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" align="center"></el-table-column> <el-table-column prop="id" label="序号" width="80" align="center" sortable></el-table-column> <el-table-column prop="courseName" label="考试课程" show-overflow-tooltip></el-table-column> <el-table-column prop="teacherName" label="监考老师" show-overflow-tooltip></el-table-column> <el-table-column prop="roomName" label="考试教室" show-overflow-tooltip></el-table-column> <el-table-column prop="examTime" label="考试时间" show-overflow-tooltip></el-table-column> <el-table-column prop="time" label="创建时间"></el-table-column> <el-table-column label="操作" width="180" align="center"> <template v-slot="scope"> <el-button plain type="primary" @click="handleEdit(scope.row)" size="mini">编辑</el-button> <el-button plain type="danger" size="mini" @click=del(scope.row.id)>删除</el-button> </template> </el-table-column> </el-table> <div class="pagination"> <el-pagination background @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[5, 10, 20]" :page-size="pageSize" layout="total, prev, pager, next" :total="total"> </el-pagination> </div> </div>
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值