vue批量删除附后台代码-若依框架

按钮

<el-button type = "danger" plain icon = "el-icon-delete" size = "mini" @click = "doDeleteButton(ids)" >批量删除</el-button>

只有管理员可删除 v-hasPermi="['system:supplier:remove']"

<el-button type = "danger" plain icon = "el-icon-delete" size = "mini" @click = "doDeleteButton(ids)" v-hasPermi="['system:supplier:remove']">批量删除</el-button>

复选框

fileList改成你自己的

<el-table :data="fileList" stripe style="width: 100%" @selection-change="handleSelectionChange">
  <el-table-column type="selection" width="55" align="center" />

import { delFilesList } from "@/api/system/";


data() {
  return {
    fileList: [],
    // 选中数组
    ids: [],

/** 批量删除 */
/** 多选框选中数据 (item => item.id) 这里的id是你自己表里的id,看好了否则后台获取不到id*/
handleSelectionChange(selection) {
  this.ids = selection.map(item => item.id)
},
/** 批量删除 */
doDeleteButton(rows) {
  if (rows.length !== 0) {
    this.$confirm('是否确认删除这' + rows.length + '条数据?', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(function () {
      return delFilesList(rows)
    }).then(() => {
      this.getList();
      this.$modal.msgSuccess("删除成功");
    })
  } else {
    this.$modal.msgSuccess("未选择数据");
  }
},


 

js

// 删除需求
export function delFilesList(ids) {
  return request({
    url: '/system/fileManagement/deleteFileManagementList/' + ids,
    method: 'delete'
  })
}

后台


/**
 * 删除
 * @param  ids
 */
@DeleteMapping("/deleteFileManagementList/{ids}")
public AjaxResult deleteFileManagementList(@PathVariable String[] ids) {
    for (String id : ids){
        fileManagementService.removeById(id);
    }
    return AjaxResult.success();
}
您好!针对您的问题,如果您使用的是Vue框架进行开发,可以按照以下步骤进行批量删除商品: 1. 创建一个复选框组件,让用户可以选择要删除的商品。 2. 在Vue组件中,使用v-model指令将复选框的值绑定到组件的数据对象中。 3. 创建一个删除按钮,并在点击时触发一个方法。 4. 在该方法中,使用axios或其他HTTP库向后端发送请求,将选中的商品ID发送到后端进行删除。 下面是一个示例代码: ```html <template> <div> <table> <thead> <th> <input type="checkbox" v-model="allChecked" @change="checkAll"/> </th> <th>ID</th> <th>商品名称</th> <th>价格</th> </thead> <tbody> <tr v-for="item in items" :key="item.id"> <td> <input type="checkbox" v-model="checkedIds" :value="item.id"/> </td> <td>{{ item.id }}</td> <td>{{ item.name }}</td> <td>{{ item.price }}</td> </tr> </tbody> </table> <button @click="deleteSelected">删除选中商品</button> </div> </template> <script> import axios from 'axios'; export default { data() { return { items: [], checkedIds: [], allChecked: false } }, created() { // 获取商品列表 this.fetchItems(); }, methods: { fetchItems() { // 发送HTTP请求获取商品列表 axios.get('/api/items').then(response => { this.items = response.data; }); }, checkAll() { // 全选/取消全选 this.checkedIds = this.allChecked ? this.items.map(item => item.id) : []; }, deleteSelected() { // 删除选中商品 axios.post('/api/delete-items', { ids: this.checkedIds }).then(() => { // 删除成功后重新获取商品列表 this.fetchItems(); }); } } } </script> ``` 在这个示例中,我们通过v-model指令将复选框的值绑定到了checkedIds数组中,当用户点击删除按钮时,会发送一个POST请求到后端,将选中的商品ID传递给后端进行删除。在删除成功后,我们重新获取商品列表,让用户看到最新的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值