Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在ReactJs+Electron中使用箭头函数:意外标记_Javascript_Reactjs_Arrow Functions - Fatal编程技术网

Javascript 无法在ReactJs+Electron中使用箭头函数:意外标记

Javascript 无法在ReactJs+Electron中使用箭头函数:意外标记,javascript,reactjs,arrow-functions,Javascript,Reactjs,Arrow Functions,我曾经在我的React原生项目中使用Javascript中的箭头函数,一切都很好 现在,我正在用Electron开发一个ReactJS应用程序,我不能做任何箭头功能 以下是一个例子: export default class App extends React.Component { constructor(props) { super(props); this.state = {nodes : [], path: 'C:/Users/',

我曾经在我的React原生项目中使用Javascript中的箭头函数,一切都很好

现在,我正在用Electron开发一个ReactJS应用程序,我不能做任何箭头功能

以下是一个例子:

export default class App extends React.Component {
    
  constructor(props) {
    super(props);
    this.state = {nodes : [],
        path: 'C:/Users/',
    }   
  };

...    

updatePath(event) {  
    this.setState({path: event.target.value});
    this.displayPath(); 
  }

handleNodeClick = (item) => { 
    if (item.type == "folder")
    {
        this.updatePath(item.path + '/');   
    }
  };

...

render() {

return {...}};
这给了我第一个等号的错误:

Uncaught SyntaxError: C:/Users/Alexy/Documents/PROJETS/SOFTLABEL/labelsoft/src/app.jsx: Unexpected token (90:18)
  88 |   
  89 |   
> 90 |   handleNodeClick = (item) => { 
     |                   ^
  91 | 
  92 |  console.log(item);
  93 |  if (item.type == "folder")
我已安装了babel,其中包括:

npm install --save-dev babel-plugin-transform-class-properties
但实际上,我不明白babel在这里做什么,箭头函数不是JS本机的?当我在React Native工作的时候,我从来没有做过什么特别的事情,一切都很有魅力,我真的很迷茫

这是我的package.json:

{
  "name": "labelsoft",
  "productName": "labelsoft",
  "version": "1.0.0",
  "description": "My Electron application description",
  "main": "src/index.js",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "eslint --cache --color --ext .jsx,.js src"
  },
  "keywords": [],
  "author": "Alexy",
  "license": "MIT",
  "config": {
    "forge": {
      "make_targets": {
        "win32": [
          "squirrel"
        ],
        "darwin": [
          "zip"
        ],
        "linux": [
          "deb",
          "rpm"
        ]
      },
      "electronPackagerConfig": {
        "packageManager": "npm"
      },
      "electronWinstallerConfig": {
        "name": "labelsoft"
      },
      "electronInstallerDebian": {},
      "electronInstallerRedhat": {},
      "github_repository": {
        "owner": "",
        "name": ""
      },
      "windowsStoreConfig": {
        "packageName": "",
        "name": "labelsoft"
      }
    }
  },
  "dependencies": {
    "@blueprintjs/core": "^3.31.0",
    "electron-compile": "^6.4.4",
    "electron-devtools-installer": "^2.2.4",
    "electron-squirrel-startup": "^1.0.0",
    "fs": "0.0.1-security",
    "path": "^0.12.7",
    "react": "^15.6.2",
    "react-dom": "^15.6.2",
    "react-hot-loader": "^3.1.3",
    "shell": "^0.5.0"
  },
  "devDependencies": {
    "babel-plugin-transform-async-to-generator": "^6.24.1",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-es2015-classes": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "electron-forge": "^5.2.4",
    "electron-prebuilt-compile": "8.2.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^15.1.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.20.6"
  }
}

有什么样的安装可以让箭头功能正常工作吗?到处都有很多关于如何使用它的信息,但没有关于如何使用它的信息。

我相信它应该是这样的:

handleNodeClick(item) {...}
整个例子:

导出默认类App扩展React.Component{ 构造器{ 超级作物; this.state={nodes:[], 路径:“C:/Users/”, } }; ... handleNodeClickitem{ 如果item.type==文件夹 { this.updatePathitem.path+'/'; } }; ... 渲染{ 返回{…};
很确定您在关闭{}时遇到问题

这是一个正在运行的演示,其中包含一些与您类似的代码:


你的代码和这篇有什么不同吗?请检查并发表评论。

谢谢你的-1,但是你能解释一下我的文章有什么问题吗?这是一个类方法吗?顺便问一下,你能提供更多的上下文吗?我没有-1你顺便说一句,只是想帮你。@sonkatamas是的,这是一个类组件,我只是添加了一些上下文,你能帮我吗整个应用程序组件如何?可能错误在于关闭{}如果我只是删除第一个=和=>,它编译时不会出错是的,但我希望arrow函数使用它来访问我类的其他函数。在这种情况下,我无法访问updatePath函数。你必须将它们与普通函数绑定我同意,但我的问题更多的是让arrow函数工作,而不是找到一个不让我们使用的技巧e他们…你需要这个插件:是的,我做了命令:npm install-save dev babel plugin transform class properties。但是我没有babelrc文件或babel.config.json,就像我以前的react原生项目一样。这是必要的吗?如果是,怎么做?我仔细检查了我的代码,我也将它粘贴到了你的网站上,没有括号问题。你能吗将您的代码粘贴到该代码沙盒中,并将链接放在此处?是否存在编译错误并不重要