小编enz*_*erg的帖子

为什么在发出POST请求后会收到OPTIONS请求?

我的前端代码:

<form action="" onSubmit={this.search}>
  <input type="search" ref={(input) => { this.searchInput = input; }}/>
  <button type="submit">??</button>
</form>

// search method:
const baseUrl = 'http://localhost:8000/'; // where the Express server runs
search(e) {
  e.preventDefault();
  let keyword = this.searchInput.value;
  if (keyword !== this.state.lastKeyword) {
    this.setState({
      lastKeyword: keyword
    });
    fetch(`${baseUrl}search`, {
      method: 'POST',
      // mode: 'no-cors',
      headers: new Headers({
      'Content-Type': 'application/json'
      }),
      // credentials: 'include',
      body: JSON.stringify({keyword})
    })
  }
}
Run Code Online (Sandbox Code Playgroud)

和我的Express.js服务器代码:

app.all('*', (req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
  res.header('Access-Control-Allow-Headers', …
Run Code Online (Sandbox Code Playgroud)

post http cors http-options-method preflight

6
推荐指数
1
解决办法
6928
查看次数

在 Ant Design 中,我们如何在 &lt;Row&gt; 中垂直居中 &lt;Icon&gt;?

请参阅我的 React 代码示例:

import React from 'react';
import { Row, Col, Icon } from 'antd';
const MyRow = () => (
  <Row type="flex" align="middle">
    <Col md={10}>Trouble is a friend</Col>
    <Col md={10}><Icon type="play-circle-o" /></Col>
    <Col md={4}><div>Lenka</div></Col>
  </Row>
);

...
Run Code Online (Sandbox Code Playgroud)

当我渲染时<MyRow />,我发现文本<Row>垂直居中很好,但<Icon>组件没有这样做。所以我的<MyRow>不好看。我希望所有的内容,不仅是文本,而且SVGin<Row>可以垂直居中。

我还尝试了其他图标库,例如react-icons-kit,它不起作用。

有没有人有想法?

css frontend reactjs antd

6
推荐指数
2
解决办法
4万
查看次数

如何将类似JSON(不是JSON)的字符串转换为对象?

我们都知道我们可以JSON.parse()用来将字符串转换'{"a":0,"b":"haha"}'为对象{a: 0, b: 'haha'}.

但是我们可以将字符串转换'{a: 0, b: "haha"}'为对象{a: 0, b: 'haha'}吗?

我正在编写一个Web爬虫,我需要在页面中获取数据.但是完整的数据不是在DOM中,而是在一个<script>元素中.所以我得到了有用的内容,<script>并将该字符串(如'window.Gbanners = [{...}, {...}, {...}, ...];')转换为类似JSON的字符串(如'{banners : [...]}').但是,我无法解析"JSON-like"字符串.有没有人有办法解决吗?

javascript json

1
推荐指数
1
解决办法
133
查看次数

标签 统计

antd ×1

cors ×1

css ×1

frontend ×1

http ×1

http-options-method ×1

javascript ×1

json ×1

post ×1

preflight ×1

reactjs ×1