我已经开始了一个项目,我在后端使用React JS作为后端的节点js.我用webpack捆绑了JS文件.我使用了babel和其他必要的东西.当我在react类中使用箭头函数时,它会产生语法错误.像模块构建失败:SyntaxError:意外的令牌.但我可以在节点中使用箭头功能,没有任何问题.
这是我的webpack配置文件
import path from 'path';
import webpack from 'webpack';
import 'react-hot-loader/patch';
export default{
devtool: 'eval',
entry:[
'react-hot-loader/patch',
'webpack-hot-middleware/client?reload=true',
path.join(__dirname,'client/index.js')],
output:{
path:'/',
publicPath:'/'
},
plugins:[
new webpack.NoErrorsPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin()
],
module:{
loaders:[
{
test:/\.js$/,
include:path.join(__dirname,'client'),
loaders: ['react-hot-loader/webpack', 'babel']
},
{
test: /\.jpe?g$|\.gif$|\.svg$|\.png$/i,
loader: 'file-loader?name=[name].[ext]'
}
]
},
resolve:{
extension:['','.js']
}
}
Run Code Online (Sandbox Code Playgroud)
我的React文件
class mapSidebar extends React.Component{
constructor(props,context){
super(props,context);
this.state = {
dataSource: []
};
this.handleUpdateInput = this.handleUpdateInput.bind (this);
}
handleUpdateInput = (value) => {
this.setState({ …Run Code Online (Sandbox Code Playgroud) 我试图通过POSTMAN从OAuth 2.0 Playground获取访问令牌。这些是配置。当请求令牌时,它说。为什么我无法获得令牌?如何解决呢?Could not complete Oauth2 login
我试图在React Js中为NLP/POS-tagger项目创建一个解析器树.我发现GoJs提供了一个很酷的解析器树GoJs-parser-tree,但是我找不到react js实现的文档.我尝试了一些例子,但我无法使用它反应继承我的代码,我需要在反应中使用它
<!DOCTYPE html>
<html>
<head>
<title>Parse Tree</title>
<meta name="description" content="A collapsible tree layout with all of the leaf nodes at the same layer." />
<!-- Copyright 1998-2016 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <!-- you don't need to use this -->
<script src="goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you …Run Code Online (Sandbox Code Playgroud) 我收到一个错误,比如 “操作必须是普通对象”。在使用 React Redux 时,使用自定义中间件进行异步操作 。我正在开发一个具有登录功能的应用程序。这是我的代码。
成分
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import Paper from 'material-ui/Paper';
import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';
import * as AuthActions from '../../actions/AuthAction';
import {blueGrey50,lightBlue500} from 'material-ui/styles/colors';
const style = {
height: 350,
width: 370,
marginLeft: 80,
marginRight: 380,
marginTop: 80,
marginBottom: 50,
textAlign: 'center',
display: 'inline-block',
backgroundColor: blueGrey50,
paddingTop: 20,
};
const style1 = {
color: lightBlue500
}; …Run Code Online (Sandbox Code Playgroud) 我试图在一个返回一个promise的函数上使用异步等待,但是我得到的输出是Promise { <pending> }.在这里我使用名为convertFiletoPDF的函数返回一个promise.我需要获取输出(我在resolve()中提到的路径).当我用它时
convertFiletoPDF(file).then((result) => {
console.log(result);
}).catch((err)=>{
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
它给出了预期的结果.下面的代码有什么问题?我对这些异步等待和承诺相当新.
function convertFiletoPDF(file) {
return new Promise(function(resolve, reject) {
unoconv.convert(file, "pdf", function(
err,
result
) {
if (err) {
reject(err);
}
let File = file.substring(file.lastIndexOf("/")+1,file.lastIndexOf("."));
// result is returned as a Buffer
fs.writeFile(__dirname+"/files/converted/"+File+".pdf", result, error => {
/* handle error */
if (err) reject(error);
else resolve("./files/converted/"+File+".pdf");
});
});
});
}
async function myfunc(file){
let res = await convertFiletoPDF(file);
return res;
}
let res = myfunc(file);
console.log(res);
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Nodejs fs 模块将 JavaScript 代码写入 js。我设法编写了一个 json 文件,但可以围绕如何向其中编写 JavaScript 进行思考。
fs.writeFile("config.json", JSON.stringify({name: 'adman'tag: 'batsman',age: 25}), 'utf8',{ flag: "wx" }, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
Run Code Online (Sandbox Code Playgroud)
我需要使用以下数据创建一个.js文件
const cricketers = [
{
name: 'adman',
tag: 'batsman',
age: 25
},
// other objects
]
module.exports = cricketers ;
Run Code Online (Sandbox Code Playgroud) 根据我的知识,什么时候有一个字符串
$a="120.43sunil"+5;
Run Code Online (Sandbox Code Playgroud)
它会给出一个结果
$a=125.43
Run Code Online (Sandbox Code Playgroud)
由于字符串不是数字,因此将省略"sunil"部分.如果我们得到一些东西怎么办?
$a="12fred34"*" 3"
Run Code Online (Sandbox Code Playgroud)
将字符串转换为1234或12034?我是perl编程的新手.
我试图使用地图功能显示一些数据,但我不断收到警告和错误。他们是
警告:React 性能测量代码中存在内部错误。没想到 componentDidMount 计时器在另一个实例的渲染计时器仍在进行中时启动。
另一个是
未捕获的类型错误:无法读取未定义的属性“地图”
我发现this.props.courses.map返回 null 但我仍然不知道为什么?
import React,{PropTypes} from 'react';
import {connect} from 'react-redux';
import * as courseActions from '../actions/courseActions';
class CoursesPage extends React.Component{
constructor(props,context){
super(props,context);
this.state={
course:[{id:1,title:'hello'}]
};
this.onTitleChange = this.onTitleChange.bind(this);
this.onClickSave = this.onClickSave.bind(this);
}
onTitleChange(event){
const course = this.state.course;
course.title = event.target.value;
this.setState({course:course});
}
onClickSave(){
this.props.dispatch(courseActions.createCourse(this.state.course));
}
courseRow(){
return this.props.courses.map((course)=>{
return(
<div key={course.id}>{course.title}</div>
);
});
}
render(){
return(
<div>
<h2>hello</h2>
<h3>{this.courseRow()}</h3>
<input type="text" onChange={this.onTitleChange} value={this.state.course.title}/>
<input type="submit" value="save" onClick={this.onClickSave}/>
</div>
);
} …Run Code Online (Sandbox Code Playgroud) 我有一个圆形的 div,显示圆形的csscircle属性是从类中获取的。圆形 div 的颜色取自内联样式。这里使用了一个调用的函数Status(),它将返回十六进制颜色代码。圆圈根据我们传递给 Status 函数的状态呈现颜色。为了实现悬停效果,我向样式对象添加了 ':hover' 属性,但它不起作用。这是我尝试过的代码。关于如何实现这一目标有什么想法吗?我需要在鼠标悬停时向圆圈添加边框/发光。
<div
className="circle"
style={{
backgroundColor: Status('new'),
':hover': {
boxShadow: `0px 0px 4px 2px ${Status('complience')}`,
},
}}
/>
Run Code Online (Sandbox Code Playgroud) javascript ×6
reactjs ×5
ecmascript-6 ×2
react-redux ×2
redux ×2
async-await ×1
babeljs ×1
css ×1
file ×1
fs ×1
gojs ×1
node.js ×1
numeric ×1
oauth-2.0 ×1
perl ×1
postman ×1
promise ×1
sass ×1
string ×1