方法一:使用every()函數,此函數不怎么常用,想要了解更多請自查
//表格 evaluateData為表格的數據 <el-table id="out-table3" :data="evaluateData" stripe style="width: 100%"> <el-table-column prop="appraiseValve" label="評價項目"> </el-table-column> <el-table-column label="評價主體" > <el-table-column prop="score" label="園長評"> <template slot-scope="scope"> <el-input v-model="scope.row.score" label="請輸入分數" style="width: 100px;"> </el-input> </template> </el-table-column> </el-table-column> </el-table> //Vue 結構下的的data data(){ return{ evaluateData:[ ] } } //提交的事件 submit(){ //此方法內的this指向 var that = this let flag = that.evaluateData.every(item => !!item.score) if (!flag) { console.log('score分數不能為空!') return }else{ //不為空時執行的結果 } }
方法二:some()函數
使用 if (this.evaluateData.some((val) => val.score== '')) { this.$message({ type: "error", message: "請填寫分數,分數不能為空, }); return; }