优化代码<uni-tr v-for="item in Now" :key="item.id" v-if="item.calltime>timenow && item.part === 0"> <uni-td align="center">{{ item.num }} {{ item.name }}</uni-td> <uni-td align="center">小部位-激光脱毛</uni-td> <uni-td align="center">{{ item.room }}号诊室</uni-td> <uni-td align="center">已叫号</uni-td> </uni-tr> <uni-tr v-for="item in Now" :key="item.id" v-if="item.calltime==null && item.part === 0"> <uni-td align="center">{{ item.num }} {{ item.name }}</uni-td> <uni-td align="center">小部位-激光脱毛</uni-td> <uni-td align="center">---</uni-td> <uni-td align="center">等待中</uni-td> </uni-tr> <uni-tr v-for="item in smallNull" :key="item"> <uni-td align="center">---</uni-td> <uni-td align="center">---</uni-td> <uni-td align="center">---</uni-td> <uni-td align="center">---</uni-td> </uni-tr>
时间: 2023-08-13 19:26:59 浏览: 118
可以将三个 <uni-tr> 合并成一个,使用 v-if 判断不同情况下的显示内容,可以减少重复代码。像这样:
```
<uni-tr v-for="item in Now" :key="item.id" v-if="item.part === 0">
<uni-td align="center">{{ item.num }} {{ item.name }}</uni-td>
<uni-td align="center" v-if="item.calltime > timenow">小部位-激光脱毛</uni-td>
<uni-td align="center" v-else>---</uni-td>
<uni-td align="center" v-if="item.calltime != null">{{ item.room }}号诊室</uni-td>
<uni-td align="center" v-else>---</uni-td>
<uni-td align="center" v-if="item.calltime != null">已叫号</uni-td>
<uni-td align="center" v-else>等待中</uni-td>
</uni-tr>
<uni-tr v-for="item in smallNull" :key="item">
<uni-td align="center">---</uni-td>
<uni-td align="center">---</uni-td>
<uni-td align="center">---</uni-td>
<uni-td align="center">---</uni-td>
</uni-tr>
```
这样可以避免重复的代码,提高代码的可读性和可维护性。
阅读全文