我的前端代码:
<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) 请参阅我的 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,它不起作用。
有没有人有想法?
我们都知道我们可以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"字符串.有没有人有办法解决吗?