iView 在Vue中使用遇到的问题

悠悠 2023-07-09 08:28 107阅读 0赞

一、Tree 树形控件

问题:

树形控件在参照官方最后一个自定义render例子时,无法对树节点进行选中

format_png

  1. return h(
  2. "span",
  3. {
  4. style: {
  5. display: "inline-block",
  6. cursor: "pointer",
  7. color: node.node.selected ? "#2d8cf0" : "#fff" //根据选中状态设置样式
  8. },
  9. on: {
  10. click: () => {
  11. if (!node.node.selected)
  12. this.$refs.tree.handleSelect(node.nodeKey); //手动选择树节点
  13. }
  14. }
  15. },

二、Table 表格 结合 Page 分页

问题:

在表格使用多选框时,分页切换后,上一页的选中状态无法保存。

解决方案:

定义一个存储所有选中的数组this.selectRow = [],选中状态发生变化时,向数组中增删选中目标。

在翻页事件中,加入下面的代码:

  1. //翻页事件
  2. changePage(page) {
  3. this.currentPage = page;
  4. this.tableData.map(row => {
  5. //判断是否在选中列表中
  6. f['_checked'] = $.inArray(row.name,this.selectRow) != -1;
  7. })
  8. }

三、Table 表格 自定义选择框、输入框

效果图:

format_png 1

示例代码:

  1. <template>
  2. <Table
  3. ref="fieldTable"
  4. :loading="fieldLoading"
  5. :columns="fieldColumns"
  6. :data="fieldTableData"
  7. @on-select="tableSelect"
  8. @on-select-cancel="tableSelectCancel"
  9. @on-select-all="tableSelectAll"
  10. @on-select-all-cancel="tableSelectAllCancel"
  11. ></Table>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. fieldColumns: [],
  18. fieldTableData: [],
  19. fieldColumns: [
  20. {
  21. type: "selection",
  22. width: 60,
  23. align: "center"
  24. },
  25. {
  26. title: "发布字段",
  27. key: "publish",
  28. align: "center",
  29. //渲染为勾选框
  30. render: (h, params) => {
  31. return h("div", [
  32. h("Checkbox", {
  33. props: {
  34. value: params.row.publish
  35. },
  36. on: {
  37. "on-change": data => {
  38. this.fieldTableData[params.row.index].publish = data;
  39. this.fieldTableData[params.row.index]["_checked"] = true;
  40. }
  41. }
  42. })
  43. ]);
  44. }
  45. },
  46. {
  47. title: "字段名称",
  48. key: "name",
  49. width: 120
  50. },
  51. {
  52. title: "字段重命名",
  53. key: "new_name",
  54. align: "center",
  55. width: 120,
  56. //渲染为输入框
  57. render: (h, params) => {
  58. return h("div", [
  59. h("Input", {
  60. props: {
  61. value: params.row.new_name
  62. },
  63. on: {
  64. "on-blur": event => {
  65. this.fieldTableData[params.row.index].new_name =
  66. event.target.value;
  67. this.fieldTableData[params.row.index]["_checked"] = true;
  68. }
  69. }
  70. })
  71. ]);
  72. }
  73. },
  74. {
  75. title: SELAN.type || "类型",
  76. key: "type",
  77. align: "center"
  78. },
  79. {
  80. title: SELAN.length || "长度",
  81. key: "length",
  82. align: "center"
  83. }
  84. ]
  85. };
  86. },
  87. methods: {
  88. //单行选择
  89. tableSelect(selection, row) {
  90. this.fieldTableData[row.index]["_checked"] = true;
  91. this.fieldTableData[row.index].publish = false;
  92. },
  93. //单行取消选择
  94. tableSelectCancel(selection, row) {
  95. this.fieldTableData[row.index]["_checked"] = false;
  96. this.fieldTableData[row.index].publish = false;
  97. },
  98. //全选
  99. tableSelectAll(selection) {
  100. this.fieldTableData.map(s => {
  101. s["_checked"] = true;
  102. });
  103. },
  104. //取消全选
  105. tableSelectAllCancel(selection) {
  106. this.fieldTableData.map(s => {
  107. s["_checked"] = false;
  108. s.publish = false;
  109. });
  110. }
  111. }
  112. };
  113. </script>

转载:https://www.cnblogs.com/sharealex/articles/10082386.html

发表评论

表情:
评论列表 (有 0 条评论,107人围观)

还没有评论,来说两句吧...

相关阅读