else-if代码简化

 watch(
      () => route.query.title,
      (newQuery, oldQuery) => {
        title.value = route.query.title ? route.query.title : "发布成果";
        const actions = {
          发布成果: GetdraftAchieve,
          发布需求: GetdraftDemand,
          发布专利: GetdraftPatent,
        };
        actions[title.value].call();
      },
      { immediate: true }
    );

    function RequestHanle(fnc) {
      //注释:check_state 0 未审核 1审核通过 2草稿箱
      return fnc({ check_state: 2 }).then((res) => {
        if (res.success) {
          draftList.value = res.data.currentPageDatas;
        }
      });
    }

    function GetdraftAchieve() {
      toPath.value = "/results/put?title=发布成果";
      editPath.value = "/results/put?title=编辑草稿";
      RequestHanle(draftAchieve);
    }

    function GetdraftDemand() {
      toPath.value = "/demands/put?title=发布需求";
      editPath.value = "/demands/put?title=编辑草稿";
      RequestHanle(draftDemand);
    }

    function GetdraftPatent() {
      toPath.value = "/patent/put?title=发布专利";
      editPath.value = "/patent/put?title=编辑草稿";
      RequestHanle(draftPatent);
    }

简化前:

//  watch(() => route.query.title,(newQuery, oldQuery) => {
    //         title.value=route.query.title
    //        if(title.value=="发布成果"){
    //         toPath.value="/results/put?title=发布成果"
    //         editPath.value="/results/put?title=编辑草稿"
    //         draftAchieve({
    //         check_state:2
    //       }).then((res)=>{
    //         if(res.success){
    //           draftList.value=res.data.currentPageDatas
    //           console.log('draftList',draftList.value)
    //         }
    //       })
    //        }
    //         else if(title.value=="发布需求"){
    //          toPath.value="/demands/put?title=发布需求"
    //         editPath.value="/demands/put?title=编辑草稿"
    //          draftDemand({
    //         check_state:2
    //       }).then((res)=>{
    //         if(res.success){
    //           draftList.value=res.data.currentPageDatas
    //         }
    //       })
    //        }
    //        else if(title.value=="发布专利"){
    //          toPath.value="/patent/put?title=发布专利"
    //         editPath.value="/patent/put?title=编辑草稿"
    //         draftPatent({
    //         check_state:2
    //       }).then((res)=>{
    //         if(res.success){
    //           draftList.value=res.data.currentPageDatas
    //           console.log('draftList',draftList.value)
    //         }
    //       })
    //        }       
	  //   },{ immediate: true });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值