Tag: reactjs

在create-react-app项目中增加JavaScript堆大小

节点通过传入–max-old-space-size命令行标志来增加堆大小。 在create-react-app项目中,一切都取决于使用react-scripts。 如何在这样的项目中传递这个参数,我应该在哪里做最好的? 谢谢你的帮助。

React Setup'npm run build'error'意外标记'b'在18:4“

目前使用本教程: http : //www.zsoltnagy.eu/step-by-step-environment-setup-of-the-react-developer-no-legacy-2016-standards/ 我以为我正确地遵循了一切,但当我尝试第七步,我得到这个错误(见图片)。 这里是我的package.json文件 – 我承认我可能改变了一些东西,同时试图让我自己的工作。 { "name": "rapp", "version": "1.0.0", "description": "\"\"", "main": "index.js", "repository": { "type": "git", "url": "\"\"" }, "keywords": [ "\"\"" ], "author": "\"BH0\"", "license": "ISC", "scripts": { "test": "\"\"" "build": "webpack -d && cp src/app/index.html dist/index.html && webpack-dev-server –hot –inline –colors –progress –content-base src/", "build-prod": "webpack -p && […]

通过节点/反应中的“新请求”,如何通过GET请求传递参数?

我在我的reactjs应用程序中有以下的API调用: static getAllSkills(title_id) { const request = new Request(`http://localhost:4300/api/v1/job_title_skills`, { method: 'GET', headers: new Headers({ 'Content-Type': 'application/json' }), body: JSON.stringify({title_id: title_id}) }); return fetch(request).then(response => { return response.json(); }).catch(error => { return error; }); } 哪一个指向一个Rails的端点,期望的参数title_id像这样: def index @skills = Skill.where(id: params[:title_id]) …. end 控制器正在期待一个GET请求但是与上述,我得到以下JS控制台错误: Uncaught TypeError: Failed to construct 'Request': Request with GET/HEAD method […]

与Webpack的ReactJS:未捕获的ReferenceError:需求未定义

以下是我的webpack.config.js。 在浏览器开发工具中,获取“Uncaught ReferenceError:require is not defined” 如果我删除“目标”:“节点”,然后错误“未捕获TypeError:fs.​​readFileSync是不是一个函数”被抛出。 var config = { entry: './main.js', output: { filename: './index.js', }, devServer: { inline: true, port: 8080 }, node: { fs: "empty" }, module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['es2015', 'react'] } } ] }, target: 'node' } module.exports = […]

服务器没有返回JSON从Express到React(代理)

我正在尝试制作一个具有React前端(在端口8080上运行)和一个Express-Node.js后端(在端口3000上)的应用程序。 我希望我的客户使用fetch从我的服务器请求数据。 到目前为止,我在线阅读的内容表明,我需要使用http://localhost:3000的值向我的package.json添加一个proxy项。 我这样做了,我的服务器正确接收请求,但它的响应不是我所期望的(一个JSON对象)。 我究竟做错了什么? //Server app.get('/search', function(req, res) { … //console.log(section) <– Is the correct value res.json(section); }) … app.listen(3000) //Client handleTouchTap() { fetch('/search?crn=10001').then(function(response) { //<– Hard-coded for testing return response; //<– Does not contain the value of "section" from server }).then(function(data) { console.log(data); //<– Likewise, does not contain the value }); } //From […]

Webpack&Babel:服务器端渲染React组件“Unexpected token”<'“

我一直在调查这个问题3天,但不能得到它的工作。 完整的错误是: C:\Users\XXXXXX\WebstormProjects\XXXX\server\routes\auth.jsx:58 return res.send(ReactDOMServer.renderToString(<LoginPage />)); ^ SyntaxError: Unexpected token < at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (C:\Users\XXXXXX\WebstormProjects\XXXX\index.js:10:20) 这是我的webpack.config.js: const path = require('path'); module.exports = { entry: path.join(__dirname, '/client/src/app.jsx'), output: { path: […]

反应:防止点击滚动条传播

我有一个可滚动的div,不幸的是我也有事件关联在div上的onMouseDown。 我的问题是,当我想通过点击滚动条滚动那些事件然后被解雇。 有没有办法让它,所以我可以防止滚动条上的鼠标事件传播?

Redux – 通过键在状态数组中查找对象并更新其另一个键

我正在使用后端的NodeJS和前端的React + Redux的CRUD应用程序。 这是一个如何运作的快速模式: 添加一个项目 用户inputpost的标题 然后将标题发送到在NodeJS中获取POST路由并通过主体发送标题的调度 在NodeJS路由中,我添加了一个新的项目集合与该标题 BACKEND DONE,新的post在服务器中 我在步骤2中添加.then()调度function,其中我派遣一个type: 'ADD_POST'并post: post (我从res.json({post: result from database}) ) 在我的reducer中,我设置了一个CASE 'ADD_POST': return action.post 完成FRONTEND后,用户现在可以看到同一个post,而不需要刷新 我想使用相同的逻辑来更新特定post的喜好 。 这是我迄今为止所做的: 点击一个post上的button会触发一个获取NodeJS PUT路由的调度 NodeJS路由查找使用ID的文章,并添加1到喜欢该post的旧值 BACKEND DONE,现在在服务器上有1个以上 我再次添加到获取NodeJS路由的调度中,在该调度中,我分配了一个type 'ADD_LIKE'的操作,并更新了更新的post ID 在reducer中,我设置了一个CASE 'ADD_LIKE':它使用下面代码片段中的代码遍历整个状态。 这是这个片段: state.map(item => { if(item.id === action.postid) { //i find the specific item, but now im stuck on how […]

在Node.js中导入React throws SyntaxError:意外的令牌导出

我试图用Node.js和React实现SSR,按照这个例子https://github.com/babel/example-node-server的build议,在官方的Babel文档中这里http://babeljs.io/docs/usage / CLI /#巴别节点 为了开发,我使用了babel-node ; 为了生产,我想用babel来传递我的服务器并运行它: 的package.json "scripts": { "start": "node ./dist/server/index.js", "dev:server": "nodemon ./src/server/index.js -x babel-node", "build:server": "babel ./src/server -d ./dist/server –copy-files -s inline" }, "babel": { "presets": [ "env", "react", "stage-2" ], "plugins": [ "transform-decorators-legacy" ] } 服务器使用ES6语法编写: SRC /服务器/ index.js import 'babel-polyfill' import './config' import Express from 'express' import bootstrap from […]

无法从React客户端向Node.js websocket服务器发送消息

我有以下代码作为服务器: var http = require('http'), cors = require('cors'), connect = require('connect'), WebSocketServer = require('ws'); var DataController = function() { this.PORT = 8090; this.startWS(); this.startServer(); } DataController.prototype = { // code to start server… getMessage: function(_message) { var that = this, message = JSON.parse(_message), msgName = message.name; console.log('new message ' + msgName); switch(msgName){ case 'start': // […]