简体   繁体   English

如何在koa中获取查询参数

[英]How to get a query parameter in koa

I am using koa.js with typescript.我正在使用带有 typescript 的 koa.js。 It will give me an error, which was describe in the below screenshot.它会给我一个错误,在下面的屏幕截图中描述。 I have also checked the typed version of koa it will definition for a query is a ParsedUrlQuery我还检查了 koa 的类型化版本,它将为查询定义是ParsedUrlQuery

const email: string = ctx.request.query.email;

在此处输入图像描述

As the error states, you are trying to set something of type 'string |如错误所述,您正在尝试设置类型为 'string | string[] |字符串[] | undefined' to something you have defined to only be a string. undefined' 到您定义为仅是字符串的内容。 Remove the 'string' type declaration on the email constant删除 email 常量上的“字符串”类型声明

const email = ctx.request.query.email;

With the amount of information you have given, I can not help solve the question you have stated in the title.以您提供的信息量,我无法帮助解决您在标题中提出的问题。 However, this will solve that error message you are getting.但是,这将解决您收到的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM