在这里,我有this.state.word is boolean type
所以价值是true/false
但是当我想尝试追加this.state.word
它给我的错误是这样argument type boolean is not assignable to parameter type string | blob
所以如何在FORMDATA追加布尔类型的值(真/假)(注: - 我想在布尔类型来发送不在字符串)?
handleSendSynopsis() {
const data = new FormData();
data.append('word', this.state.word);
}
使用JSON.stringify在客户端发送数字和布尔值,然后解析它的后端
例如
const form = new FormData;
const data = {
name: 'john doe',
active: true,
count: 42
};
form .append('file', file); // send your file here
form .append('fileProps', JSON.stringify(data));
据FormData Documentation,FormData.append
只接受USVString
或Blob
。是你将有你的数据转换为字符串,然后后来在后端解析它。您可以使用JSON.stringify
到表单对象转换为字符串。