Vue-单行删除与批量删除

一、单行删除

<el-table-column align="center" fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" icon="el-icon-edit"></el-button>
            <el-button
              @click="handleClick(scope.row)"
              type="text"
              size="small"
              icon="el-icon-delete"
            ></el-button>
          </template>
</el-table-column>

在对应的删除按钮添加事件scope.row保证选中当前行

export default {
  data() {
    const data = [];
    return {
          //删除记录的code
      deleteCode: []
    };
  },
methods: {
    //Table里的点击删除图标\
    async handleClick(row) {
      const confirmResult = await this.$confirm(
        "此操作将永久删除该文件, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).catch(err => err);
      if (confirmResult !== "confirm") {
        return this.$message.info("已取消!");
      }
      this.deleteCode.push(row.id);
	   //调用的删除接口
      const { data: res } = await this.$axios.delete(
        "/questionCheck/updateIsDelete/" + this.deleteCode,
        {
          data: this.deleteCode
        }
      );
      if (res.code != "SUCCESS") {
        return this.$message.error("删除信息失败!");
      }
      this.deleteCode = [];
    },
}

二、批量删除

<el-button @click="batchDeleteBuild(multipleSection)" plain>批量删除</el-button>
export default {
  data() {
    return {
	      //被选中的列表记录
	    multipleSection: [],
       };
   },
methods: {
       //批量删除选中数据方法
    async batchDeleteBuild() {
      //判断是否选择了数据
      if (this.multipleSection.length == 0) {
        alert("请选择要删除的数据");
        return;
      }
      //如果有选中的数据,那么弹出消息框
      const confirmDelete = await this.$confirm(
        "此操作会永久删除建筑信息,是否删除?",
        "提示",
        {
          confimrButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).catch(err => err);
      //如果用户确认删除,则返回字符串confirm
      //如果用户取消删除,则返回字符串cancel
      if (confirmDelete !== "confirm") {
        return this.$message.info("已取消");
      }
      //将选中的数据推到deleteCode数组中
      for (var i = 0; i < this.multipleSection.length; i++) {
        var j = i;
        var id = this.multipleSection[j].id;
        this.deleteCode.push(id);
      }
      //删除deleteCode中的数据
      const { data: res } = await this.$axios.delete(
        "/question/DeleteQuestionBatch",
        {
          data: this.deleteCode
        }
      );
      if (res.code != "SUCCESS") {
        return this.$message.error("删除课程信息失败!");
      }
      this.deleteCode = [];
    },
}

 

  • 33
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 27
    评论
vue-print-nb是一个Vue.js的插件,用于在浏览器中打印指定的内容。它可以通过配置参数来实现批量打印URL。 以下是使用vue-print-nb批量打印URL的步骤: 1. 在终端中执行以下命令安装vue-print-nb插件: ```shell npm i vue-print-nb ``` 2. 在main.js文件中全局引入vue-print-nb插件: ```javascript import Print from 'vue-print-nb'; Vue.use(Print); ``` 3. 在Vue组件中,使用v-for指令循环生成多个包含URL的元素,例如: ```html <template> <div> <div v-for="(url, index) in urlList" :key="index"> <img :src="url" style="width: 100px; height: 100px"> </div> <el-button @click="printUrls">打印</el-button> </div> </template> ``` 4. 在Vue组件的data中定义urlList数组,用于存储要打印的URL列表: ```javascript data() { return { urlList: [ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg', 'https://example.com/image3.jpg' ] } } ``` 5. 在Vue组件的methods中定义printUrls方法,用于触发打印操作: ```javascript methods: { printUrls() { this.$print({ ids: this.urlList.map((url, index) => `imagePrint${index}`), popTitle: "批量打印URL" }); } } ``` 在上述代码中,我们使用v-for指令循环生成多个包含URL的div元素,并为每个div元素设置了一个唯一的id(例如imagePrint0、imagePrint1、imagePrint2)。然后,在printUrls方法中,我们通过this.$print方法调用vue-print-nb插件的打印功能,传递了要打印的元素的id列表和打印配置参数。 这样,当点击"打印"按钮时,vue-print-nb插件会将指定的URL批量打印出来。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值