$route 在 typescript 赋值时报错

958 阅读1分钟
data() {
    return {
      workflowId: ""
    };
  },
  ...
this.workflowId = this.$route.query.workflowId;

报错: Type 'string | (string | null)[]' is not assignable to type 'string'. Type '(string | null)[]' is not assignable to type 'string'.

没发现好的解决办法,先如下处理

this.workflowId = this.$route.query.workflowId as string;