«

一个方法想到传递到组件很深处然后调用到页面刷新

yang 发布于 阅读:523 项目


//用下面这个属性抛出相应的方法 
provide() {
    return {
      getTaskList: this.getTaskList 
    };
  },
//在需要的组件内用inject接收到这个方法
  inject: ["getTaskList", "taskInfo"],

用refresh这个刷新组件数据(使用组件的地方)

    <BasicInformation ref="BasicInformation" @getTaskList="getTaskList" :itemGuid="itemGuid" @refresh="refresh" />
  methods: {
    refresh(newVal) {
      if (newVal) {
        // this.subtasks = newVal;
        // this.tableData = newVal.children;
        this.$emit("refresh", newVal);
      }
    },
  }

在组件内部调用其他组件

<el-tab-pane :label="taskIntel.childrenSize > 0 ? `子任务 (${taskIntel.childrenSize})` : '子任务'" name="second">
          <Subtasks
            ref="Subtasks"
            v-show="activeName === 'second'"
            @refresh="refresh"
            :taskIntel="taskIntel"
            :itemGuid="itemGuid"
            @taskInfo="taskInfo" />
        </el-tab-pane>

刷新需要的数据

 refresh(newVal) {
      if (newVal) {
        // this.subtasks = newVal;
        // this.tableData = newVal.children;
        // this.$emit("refresh", newVal);
        this.taskIntel = newVal;
      }
    },

具体方法里面调用

//任务详情获取
    taskInfo(pid, type) {
      if (!this.taskId) {
        return;
      }
      let oParam = {
        taskId: pid || this.taskId
      };
      TaskinfoApi(oParam).then((res) => {
        if (type === "refresh") {
          this.$emit("refresh", res.obj);
          // this.taskIntel = res.obj;
          return;
        }
        this.taskIntel = res.obj;
        this.zrUserId = this.taskIntel.zrUserId;
        this.userkey = this.taskIntel.zrUserId;
        this.form.taskName = this.taskIntel.zrUser;
        this.$forceUpdate();
        this.getMyuser();
        this.getUser();
        this.title = res.obj.projectName;
      });

当调用方法时type为refresh时就调用刷新

 // 置顶任务
    TopTask() {
      if (!this.taskIntel.parentId) {
        // this.$message.error("请先选择父任务");
        return;
      }
      let oParam = {
        taskId: this.taskIntel.guid
      };
      ApiTaskprosettop(oParam).then((res) => {
        if (res.code == "200") {
          this.taskInfo(this.taskIntel.parentId, "refresh");
          this.getTaskList();
          this.dialogVisible = false;
          this.$message.success("置顶成功");
        }
      });
    },

版权所有:微4e
文章标题:一个方法想到传递到组件很深处然后调用到页面刷新
除非注明,文章均为 微4e 原创,请勿用于任何商业用途,禁止转载

推荐阅读:


扫描二维码,在手机上阅读
请先 登录 再评论