问题描述

传参时,router.push中布尔值变量会给出一个错误提示

  setup(){
    const router = useRouter();

    /** 查看已办任务的流程记录 **/
    const handleFlowRecord  = (row) => {
      console.log(row)

      const procInsId = row.procInsId;
      const deployId = row.deployId;
      const taskId = row.taskId;
      
      router.push({
        path: '/flow/my/process/submit',
        query: {
          procInsId: procInsId,
          deployId: deployId,
          taskId: taskId,
          finished: true,
        }
      })
    }

    return {
      handleFlowRecord
    }
  },

编辑器提示如下错误

Argument type 
{path: string, query: 
{procInsId: any, finished: boolean, deployId: (any | null), taskId: any}} 
is not assignable to parameter type RouteLocationRaw 

查阅可知,router.push是使用字符串传递参数的,并不支持布尔类型,也就是如下图

finished: true    ×
finished: "true"

解决方法

所以我们应该使用 eval()

它的作用是把对应的字符串解析成js代码并运行

经过修改如下


  setup(){
    const router = useRouter();


    /** 查看已办任务的流程记录 **/
    const handleFlowRecord  = (row) => {
      console.log(row)

      const procInsId = row.procInsId;
      const deployId = row.deployId;
      const taskId = row.taskId;

      router.push({
        path: '/flow/my/process/submit',
        query: {
          procInsId: procInsId,
          deployId: deployId,
          taskId: taskId,
          finished: eval("true"),
        }
      })

    }

    return {
      handleFlowRecord
    }
  },
Logo

前往低代码交流专区

更多推荐