Vue + Element 表格:采购数量为0时弹出提示框
<p>"<template>\n <div>\n <el-table :data="tableData">\n <el-table-column prop="name" label="名称">\n </el-table-column>\n <el-table-column prop="purchaseQuantity" label="采购数量">\n <template slot-scope="scope">\n <el-input v-model="scope.row.purchaseQuantity" @change="checkPurchaseQuantity(scope.row)">\n </el-input>\n </template>\n </el-table-column>\n </el-table>\n </div>\n</template>\n\n<script>\n export default {\n data() {\n return {\n tableData: [\n { name: "商品A", purchaseQuantity: 0 },\n { name: "商品B", purchaseQuantity: 0 },\n { name: "商品C", purchaseQuantity: 0 }\n ]\n };\n },\n methods: {\n checkPurchaseQuantity(row) {\n if (row.purchaseQuantity === 0) {\n this.$confirm("采购数量不能为零", "提示", {\n confirmButtonText: "确定",\n type: "warning"\n });\n }\n }\n }\n};\n</script>\n" 在上面的代码中,tableData 是存储表格数据的数组,其中每个对象包含商品的名称和采购数量。checkPurchaseQuantity 方法用于检查采购数量是否为 0,并通过 this.$confirm 方法弹出提示框。需要注意的是,this.$confirm 方法返回一个 Promise 对象,可以通过 .then 方法来处理用户点击确定按钮后的逻辑。这样,当在表格中输入采购数量为 0 时,就会弹出提示框提示用户采购数量不能为零。</p>
原文地址: https://www.cveoy.top/t/topic/qghh 著作权归作者所有。请勿转载和采集!