我目前在package.json中有以下脚本,用于删除我的bundle文件夹中的所有".js"文件,以便我运行"npm run build".它在开发服务器中运行时工作正常,但在Windows机器上运行时会中断.
{
"scripts": {
"build": "rm bundles/*.js && webpack",
},
}
Run Code Online (Sandbox Code Playgroud)
由于我正在对所有构建文件进行哈希处理,因此我需要在添加新文件之前将它们全部删除,这样我就不会得到一堆旧版本.
是否有适用于Mac和Windows的"rm bundles/*.js"?
我发现了一个类似的问题,但是没有理解任何答案(并且问题被低估了)所以我在这里:
我正在尝试使用基于D3构建的库,称为Greuler,以便动态呈现图形.它的npm包似乎被破坏了.当我换掉Greuler CDN时,我的index.html里面的测试图终于奏效了.
但是,我正在研究React应用程序,我希望从React组件呈现图形.这里出现问题:react组件不使用我的index.html中的Greuler CDN脚本,我尝试了多种方法在组件内运行脚本,但似乎没有任何工作.
两个主要错误是:
error 'greuler' is not defined (在我的组件中)
Uncaught TypeError: Cannot read property 'getAttribute' of null (在D3代码中)
我的工作index.html,带有硬编码图形,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Navigating Spinoza</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js"></script>
<script src="http://marvl.infotech.monash.edu/webcola/cola.v3.min.js"></script>
<script src="http://maurizzzio.github.io/greuler/greuler.min.js"></script>
</head>
<body>
<div id="root"></div>
<div class="row" id="demo">
<script>
var instance = greuler({
target: '#demo',
width: 480,
height: 500,
data: {
nodes: [
{id: 0, label: "E1Def3", r: 25},
{id: 1, label: "E1P4", r: 15},
{id: 2, label: "E1P2", r: …Run Code Online (Sandbox Code Playgroud) 如何在 javascript 中获取缓冲图像的大小(以字节为单位)?我不允许在客户端信任文件大小,需要在后端验证作为上传验证的一部分。我的设置如下:
1-我在客户端上传一个文件并将其从 React 组件发送到 Node:
fileUpload() {
const url = '/.../...'
const formData = new FormData()
formData.append('file', this.state.file)
formData.append('actualSize', this.state.file.size) //not allowed to use this.
const config = { headers: { 'content-type': 'multipart/form-data' } }
axios.post(url, formData, config)
}
Run Code Online (Sandbox Code Playgroud)
2- 使用一些中间件,我将 Node 中的数据作为对象接收:
{
file: {
name: 'test',
data: <Buffer 12 50 4e ... >,
encoding: '7bit',
mimetype: 'image/png',
}
}
Run Code Online (Sandbox Code Playgroud)
如何测量缓冲区的字节大小?提前致谢!
我需要从客户端向我的 Node.js 服务器发送 multipart/form-data POST(xliff 文件),然后在 Node.js 中捕获数据并将该 POST 转发到另一个 Java 服务。
我已经使用multer和express-fileupload来解析表单数据流并在 Node.js 中捕获 xliff 的缓冲区,并且两者都给了我文件及其内容作为缓冲区就好了。
但是,我似乎无法在 Node 层中重新创建 FormData 对象以将 POST 转发到 Java 服务。
我继续收到错误消息“连接终止解析多部分数据”或从 Java 服务中根本没有响应。
我还尝试使用该tmp库在本地创建一个临时文件来写入缓冲区,然后尝试FormData('file', fs.createReadStream(<path>))这样做,但这对我来说似乎也不起作用......尽管我不确定我是否做得正确。
doPOST直接从浏览器使用完全相同的请求工作正常,但是一旦我尝试捕获节点层中的调用,然后将 POST 转发到 Java 服务,它就不再适用于我了。
.
const multer = require('multer');
const upload = multer();
router.post('/', upload.any(), (req, res) => {
const { headers, files } = req;
console.log('--------------- files:', files[0]); // object with buffer, etc.
const XMLString = files[0].buffer.toString('utf8'); // …Run Code Online (Sandbox Code Playgroud) 基本问题:
React.ReactElementvs和之间的区别是什么JSX.Element?它们是一样的,我什么时候应该使用每个?
我已经看到多个人提出这个问题了,没有一个答案对我有用.
我正在尝试使用react/axios对google maps api进行API调用.
这是我的获取请求:
componentDidMount() {
axios({
method : 'get',
url : `http://maps.googleapis.com/maps/api/js?key=${key}/`,
headers: {
"Access-Control-Allow-Origin": '*'
"Access-Control-Allow-Methods": 'GET',
},
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/js?
key=xxxxxxxxx/. Response to preflight request doesn't pass access control
check: No 'Access-Control-Allow-Origin' header is present on the
requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
我读过其他人都指向https://www.html5rocks.com/en/tutorials/cors/的文章con CORS
但我找不到我的问题的答案.
我正在尝试制作一个按钮,仅在验证正确完成后将用户重定向到新页面。
有没有办法做这样的事情?如何在类方法内激活路由?
import validator from './validator';
class Example {
constructor(props) {
super(props)
this.saveAndContinue = thos.saveAndContinue.bind(this)
}
saveAndContinue () {
var valid = validator.validate(this.props.form)
if (valid) {
axios.post('/path')
<Redirect to='/other_tab'>
} else {
validator.showErrors()
}
}
render() {
<button onClick={this.saveAndContinue}>Save and Continue</button>
}
}
Run Code Online (Sandbox Code Playgroud) 我知道有很多问题,但我似乎无法让它工作:我需要从通过路由呈现的子组件访问"历史".(它从redux容器接收道具).
我需要将历史对象传递给在每个Route中呈现的组件,以便我可以this.props.history.push('/route')在子组件中.之前这个应用程序的动态性较差,所以每个Route都用一个硬编码component={someComponent}; 但我发现在动态执行路由时,您需要使用render={() => <someComponent />}.
在将路由更改component={}为render={() => ...}I之后,在子组件中丢失了历史记录.
我的代码是这样的:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Link, Route, Redirect } from 'react-router-dom';
import { Nav_Item } from '.'
import DynamicTab from '.';
export default class NavBar extends React.Component {
constructor(props) {
super(props);
this.state={}
}
render() {
let tabs = [];
let routes = [];
this.props.tabs.forEach( function(tab, index) {
tabs.push(<Nav_Item key={tab.name} path_name={'/' + …Run Code Online (Sandbox Code Playgroud) 我有一个npm导入的组件(CKEditor),只关心它在安装时的父组件的状态.即,无论父组件的状态发生什么变化,CKEditor都不会反映这些变化(如果已经安装).
这对我来说是个问题,因为当父组件更改其语言道具时,我需要CKEditor根据父组件的状态进行更改.
有没有办法让我从子组件中卸载并重新装载子组件?例如,有没有办法让我根据父组件的"componentWillReceiveProps"卸载并重新安装子组件?
import React from 'react';
import CKEditor from "react-ckeditor-component";
export default class EditParagraph extends React.Component {
constructor(props) {
super(props)
this.state = {
// an object that has a different html string for each potential language
content: this.props.specs.content,
}
this.handleRTEChange = this.handleRTEChange.bind(this)
this.handleRTEBlur = this.handleRTEBlur.bind(this)
}
/**
* Native React method
* that runs every time the component is about to receive new props.
*/
componentWillReceiveProps(nextProps) {
const languageChanged = this.props.local.use_lang != nextProps.local.use_lang;
if (languageChanged) {
// how do …Run Code Online (Sandbox Code Playgroud) 我有一个可重用的反应组件存储库和仪表板存储库。
我的仪表板使用了可重用存储库中的许多组件,但我在仪表板存储库上有一个测试无法通过。
可重用组件仓库有以下版本,全部测试通过:
"emotion": "9.1.0",
"react-emotion": "9.1.0",
"jest-emotion": "^9.0.0",
"react-test-renderer": "16.6.3",
Run Code Online (Sandbox Code Playgroud)
仪表板存储库有以下版本,只有一个测试被破坏:
"emotion": "9.2.11",
"react-emotion": "9.2.11",
"jest-emotion": "9.2.11",
"react-test-renderer": "16.6.3",
Run Code Online (Sandbox Code Playgroud)
损坏的测试用于react-test-renderer制作组件的快照。正在测试的组件之一如下所示:
import styled from 'react-emotion';
import { Column } from '@commons/components';
export const StyledButtonContainer = styled('div')`
margin-top: 20px;
display: flex;
button {
flex: 1;
margin-right: 15px;
&:last-child {
margin-right: 0;
}
}
`;
Run Code Online (Sandbox Code Playgroud)
错误堆栈:
console.error node_modules/jest-emotion/dist/index.js:260
{
Error: undefined:1:627: property missing ':'
at error (/Users/path/to/my/node_modules/css/lib/parse/index.js:62:15)
at declaration (/Users/path/to/my/node_modules/css/lib/parse/index.js:224:33)
at declarations (/Users/path/to/my/node_modules/css/lib/parse/index.js:253:19)
at rule (/Users/path/to/my/node_modules/css/lib/parse/index.js:561:21)
at rules (/Users/path/to/my/node_modules/css/lib/parse/index.js:118:70)
at …Run Code Online (Sandbox Code Playgroud) 我正在 ReactJS 中创建一个“加载图片”组件。我的组件将加载的图像存储在内存中并将其发送到使用 npm“文件加载器”的节点服务器。
图像作为缓冲区到达服务器<Buffer 89 12 00 .... >
我将尝试将缓冲区保存到 MySQL,但如果数据库插入成功,则需要在浏览器中将图像显示为缩略图。
如何在浏览器中显示缓冲图像?
我在 React 应用程序中使用 react-quill 作为富文本编辑器。
我必须将文本编辑器的内容存储在本地 React 状态中,并且只将值发送到 Redux 'onBlur'。我的问题是,在获得焦点后,当您单击文本编辑器之外的按钮时,onBlur 将不起作用。(即,onBlur 在单击屏幕上的非交互式元素时起作用,但在单击“保存”按钮时不起作用)。
当前代码:
class TextEditor extends React.Component {
constructor(props) {
super(props)
this.state={
content: this.props.content;
}
this.handleQuillEditor_change = this.handleQuillEditor_change.bind(this)
this.handleQuillEditor_update = this.handleQuillEditor_update.bind(this)
}
handleQuillEditor_change (value) {
// handleChange...
}
handleQuillEditor_update () {
console.log('blur activated!')
}
render() {
const cmsProps = this.props.cmsProps
return (
<div style={containerStyle}>
<ReactQuill value={this.state.content}
onChange={this.handleQuillEditor_change}
onBlur={this.handleQuillEditor_update}/>
</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)