我正在将数据发送到我的服务器,该服务器根据请求创建一个 pdf 文件,该文件创建正常,但我无法将文件发送回客户端。我正在使用 React 提交表单
handleSubmit(event) {
event.preventDefault();
var body = {
id: this.state.id,
text: this.state.text
}
fetch('http://localhost:5000/pdf', {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json'
},
}).then(function(file) {
window.open(file.url);
});
}
Run Code Online (Sandbox Code Playgroud)
它打开http://localhost:5000/pdf,但由于我没有 GET 路由,所以没有下载。这是我的 POST 路线
router.post('/pdf', async function(req, res) {
var makePdf = require('./file-create/pdf.js');
makePdf(req, res);
});
Run Code Online (Sandbox Code Playgroud)
并且文件被返回为 pdfDoc.pipe(res);
我不能只使用 GET 路由,因为我无法以这种方式发送数据,我如何才能将此文件发送到客户端?
我正在使用 admin-on-rest 但在尝试连接到 github api 时出现错误
错误:
HTTP 响应中缺少 X-Total-Count 标头。jsonServer REST 客户端期望资源列表的响应包含此标头以及构建分页的结果总数。如果您使用 CORS,您是否在 Access-Control-Expose-Headers 标头中声明了 X-Total-Count?
和
警告:缺少键的翻译:“HTTP 响应中缺少 X-Total-Count 标头。jsonServer REST 客户端期望资源列表的响应包含此标头以及构建分页的结果总数。如果您是使用 CORS,您是否在 Access-Control-Expose-Headers 标头中声明了 X-Total-Count?”
我尝试添加 X-Total-Count 标头,但随后出现新错误
render() {
const httpClient = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({Accept: 'application/json'});
}
// add your own headers here
options.headers.set('X-Total-Count', '32');
return fetchUtils.fetchJson(url, options);
}
const restClient = jsonServerRestClient('https://api.github.com', httpClient);
return (
<Admin restClient={restClient}>
<Resource name="users" list={PostList}/>
</Admin>
);
}
Run Code Online (Sandbox Code Playgroud)
无法加载https://api.github.com/users?_end=10&_order=DESC&_sort=id&_start=0 …
我有一个带有一些切换功能的 div
<div className={styles.divStyle} onMouseEnter={this.hover} onMouseOut={this.hover}>
Run Code Online (Sandbox Code Playgroud)
这是函数
constructor(props) {
super(props);
this.state = {
isToggle: false
};
this.hover = this.hover.bind(this);
}
hover(e) {
this.setState({
isToggle: !this.state.isToggle
});
}
Run Code Online (Sandbox Code Playgroud)
它的作用是切换该 div 内某些图标的显示隐藏和显示块
<i style={{display: this.state.isToggle ? 'block': 'none'}} class="fa fa-chain"/>
Run Code Online (Sandbox Code Playgroud)
但是每当我将鼠标悬停在 div 内的图标或图像上时,它都会算作鼠标移出,我希望 div 内的项目算作切换功能的 div,我制作了我在代码笔。将鼠标悬停在图像或文本上