react axios 发送post请求的时候字符串 “null” 如何修改为 null ?
这个是一个编辑页面
json 数据
{
"id": 1,
"username": "monic_lope",
"firstname": "Moni",
"lastname": null,
"description": "\u00abMemoria selectiva ",
"avatar": "5e5183e40e548.jpg",
"email": "sweetmg@gmail.com",
"account_id": "143914624",
"followers": 12560,
"posts": 6589,
"following": 12560,
"rate": "13.50",
"grade": null,
"affiliate": null,
"avg_likes": 1384,
"avg_comments": 29,
"phone": null,
"status": "success",
"web": null,
"facebook": null,
"youtube": null,
"address": null,
"city": null,
"postal_code": null,
"region": null,
"fee": null,
"created_at": "2020-02-06T18:47:20.000000Z",
"updated_at": "2021-04-22T13:47:06.000000Z",
}
import React, {useState, useMemo, useEffect} from 'react';
import {Layout, Page, Stack, Badge, PageActions} from '@shopify/polaris';
import axios from 'axios';
const InfluencersEdit = (props: any) => {
const [item, setItem] = useState({
id: '',
username: '',
firstname: '',
lastname: '',
email: '',
phone: '',
tags: '',
followers: '',
posts: '',
following: '',
rate: '',
description: '',
address: '',
city: '',
region: '',
postal_code: '',
facebook: '',
youtube: '',
status: '',
avg_comments: '',
avg_likes: '',
});
useEffect(() => {
axios.get('/api/influencers/' + influencer).then(res => {
setItem(res.data);
});
}, []);
const handleinfluencersUpload = () => {
let formData = new FormData();
//@ts-ignore
formData.append('file', file);
formData.append('username', item.username);
formData.append('firstname', item.firstname);
formData.append('lastname', item.lastname);
formData.append('email', item.email);
formData.append('phone', item.phone);
formData.append('followers', item.followers);
formData.append('posts', item.posts);
formData.append('following', item.following);
formData.append('rate', item.rate);
formData.append('description', item.description);
formData.append('address', item.address);
formData.append('city', item.city);
formData.append('region', item.region);
formData.append('postal_code', item.postal_code);
formData.append('facebook', item.facebook);
formData.append('youtube', item.youtube);
formData.append('status', item.status);
formData.append('tags', selectedOptions.join(', '));
formData.append('_method', 'put');
axios
.post(`/api/influencers/${item.id}`, formData)
.then(res => {})
.catch(error => {});
};
}
//采用了shopify polaris的 TextField
<div className="_2iE3d">
<TextContainer spacing="tight">
<TextField
label="粉丝互动率"
type="number"
value={item.followers.toString()}
onChange={value => {
setItem({
...item,
followers: value,
});
}}
/>
</TextContainer>
</div>
请求:
响应
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但是你 tags 里面是 null 呀。你看看你那个写的和别的有什么不同。
因为你这个走的
form-data
,null
这个概念是 json 的,所以你走application/json
才可以。或者你判断一下,如果没有值就别 append 了。undefined 和 null 都一样。