📂前端
🔖前端
2025-01-14 16:48阅读: 5评论: 0推荐: 0

【VUE】页面跳转实现动态样式控制

【VUE】父子组件联动实现动态样式控制


跳转得到的参数大概有这些:

    handleToPage: function (action, id, key = "form", queryParam = {}) {
      this.$router.push({
        path: `${this.routeKey}/${key}/${action}${id ? "/" + id : ""}`,
        query: queryParam
      });
    }

首先要接收用得上的参数

  mounted () {
    const action = this.$route.params.action;
    this.isShowStar = action === "add" || action === "edit";
    this.updateColumnClasses();
  },

编写对应的方法

 updateColumnClasses: function () {
      // 指定需要添加样式的列
      const requiredColumns = [影响的列];
      // 函数:更新指定列数组中的类名
      const updateRequiredClassForColumns = (columns) => {
        columns.forEach(column => {
          if (requiredColumns.includes(column.dataIndex)) {
            column.className = this.isShowStar ? "form-table-col--required" : "";
          }
        });
      };
      // 更新所有相关列的样式
      updateRequiredClassForColumns(this.被操作列表);
    }
  }

比如:

   columns: [
        {
          title: "#",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: "费用类型",
          align: "center",
          width: 250,
          dataIndex: "type",
          // class: "form-table-col--required",
          className: "",
          scopedSlots: { customRender: "type" }
        },
        {
          title: "报销金额(元)",
          align: "center",
          width: 250,
          // class: "form-table-col--required",
          className: "",
          dataIndex: "recipientAmount",
          scopedSlots: { customRender: "recipientAmount" }
        },
        {
          title: "报销详情",
          align: "center",
          // class: "form-table-col--required",
          className: "",
          dataIndex: "detail",
          scopedSlots: { customRender: "detail" }
        }
      ],

对应着

    updateColumnClasses: function () {
      // 指定需要添加样式的列
      const requiredColumns = ["type", "recipientAmount", "detail"];
      // 函数:更新指定列数组中的类名
      const updateRequiredClassForColumns = (columns) => {
        columns.forEach(column => {
          if (requiredColumns.includes(column.dataIndex)) {
            column.className = this.isShowStar ? "form-table-col--required" : "";
          }
        });
      };
      // 更新所有相关列的样式
      updateRequiredClassForColumns(this.columns);
    }
posted @   萌狼蓝天  阅读(5)  评论(0编辑  收藏  举报
历史上的今天:
2024-01-14 【前端】2024年 前端Base64编码的中文处理问题
2024-01-14 【Vue】前端直接显示MySQL Datatime时间,显示为英文如何处理
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开