我需要从Vue3中的URL中获取选择id,以便在调用的后面的axios调用中使用它作为查询参数。我的网址是"http://localhost:8080/#/requestPIN/py6lzerjwjntl4dmr9n77e6x73blk925?electionId=thirdElection“
我想做的是:
get ID(): string | undefined {
return this.$route.query.electionId}
这给了我一个打字稿错误:
Type 'LocationQueryValue | LocationQueryValue[]' is not assignable to type 'string | undefined'. Type 'null' is not assignable to type 'string | undefined'.URL查询参数的正确类型是什么?
发布于 2022-11-04 12:58:31
断言id是一个字符串,然后在返回类型中确保它仍然可能返回undefined。
get ID(): string | undefined {
return this.$route.query.electionId as string;
}https://stackoverflow.com/questions/74316050
复制相似问题