当前位置:   article > 正文

创建灵活的表单布局,每行显示不同长度的输入框

创建灵活的表单布局,每行显示不同长度的输入框

1.项目中需要对表单中某一行的位置进行移动,但是会遇到问题,比如:有时一行需要显示一个输入框,有时一行需要显示两个输入框,你根据后端返回的数据进行循环渲染,就会有问题,利用row和col布局,一行显示一个是没有问题的,但是如果一行显示两个就会有问题,移动位置也会出现问题,搞了一下午,终于整出来了,特此记录一下。

2.话不多说,直接展示

  1. computed: {
  2. inputRows() {
  3. // Group inputs into rows based on isShort value
  4. const rows = [];
  5. let currentRow = [];
  6. //this.entityData是后端返回的数据
  7. for (const input of this.entityData) {
  8. if (currentRow.length === 0 || input.isShort === currentRow[0].isShort) {
  9. currentRow.push(input);
  10. } else {
  11. rows.push(currentRow);
  12. currentRow = [input];
  13. }
  14. }
  15. if (currentRow.length > 0) {
  16. rows.push(currentRow);
  17. }
  18. return rows;
  19. }
  20. },

应该我不说你们也应该知道computed是干什么的

之后就是渲染的问题了

  1. <a-row v-for="(rowInputs, rowIndex) in inputRows" :key="rowIndex">
  2. <a-col v-for="input in rowInputs" :key="input.order" :span="getColSpan(input.isShort)">
  3. <input type="text" :placeholder="input.label" class="input-field" />
  4. </a-col>
  5. </a-row>

 现在基本就差不多了,之后你就可以根据你自己的项目需求在进行修改即可。

觉得还不错的话,一键三连哦!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/226003
推荐阅读
相关标签
  

闽ICP备14008679号