传播运算符不工作 ...this.state.attributes
Posted
技术标签:
【中文标题】传播运算符不工作 ...this.state.attributes【英文标题】:Spread Operator is not working ...this.state.attributes 【发布时间】:2019-01-23 01:04:07 【问题描述】:扩展运算符不工作
<button ...this.state.attributes></button>
Getting error "unexpected token this" 下面是我们使用过的 package.json
"name": "@coreui/coreui-free-react-admin-template",
"version": "2.0.5",
"description": "CoreUI React Open Source Bootstrap 4 Admin Template",
"license": "MIT",
"private": true,
"dependencies":
"@coreui/coreui": "^2.0.2",
"@coreui/coreui-plugin-chartjs-custom-tooltips": "^1.2.0",
"@coreui/icons": "0.2.0",
"@coreui/react": "^2.0.4",
"@rowno/sparkline": "^3.0.1",
"all": "0.0.0",
"availity-reactstrap-validation": "^2.0.2",
"bootstrap": "^4.1.1",
"chart.js": "^2.7.2",
"classnames": "^2.2.6",
"core-js": "^2.5.7",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"flag-icon-css": "^3.0.0",
"font-awesome": "^4.7.0",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-avatar": "^3.1.0",
"react-bootstrap": "^0.32.1",
"react-chartjs-2": "^2.7.2",
"react-checkbox-group": "^4.0.1",
"react-confirm-alert": "^2.0.5",
"react-dom": "^16.4.1"
"react-loadable": "^5.4.0",
"react-loading": "^2.0.3",
"react-redux": "^5.0.7"
"react-render-html": "^0.6.0",
"react-router-config": "^1.0.0-beta.4",
"react-router-dom": "^4.3.1",
"react-sortable-pane": "^1.0.2",
"react-sparklines": "^1.7.0",
"react-spinners": "^0.3.2",
"react-stepzilla": "^4.7.2",
"react-switch": "^3.0.4",
"react-table": "^6.8.6",
"react-tabs": "^2.2.2",
"react-test-renderer": "^16.4.1",
"react-timekeeper": "^1.0.7",
"react-toastify": "^4.1.0",
"reactstrap": "^6.1.0"
"redux": "^4.0.0",
"redux-thunk": "^2.3.0"
,
"devDependencies":
"babel-jest": "^23.0.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"node-sass-chokidar": "^1.3.0",
"npm-run-all": "^4.1.3",
"react-scripts": "^1.1.4"
,
"scripts":
"build-css": "node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss",
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss --watch --recursive",
"start-js": "react-scripts start",
"start": "npm-run-all -p watch-css start-js",
"build-js": "react-scripts build",
"build": "npm-run-all build-css build-js",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
,
"babel":
"presets": [
"es2015",
"react",
"stage-0"
]
,
"bugs":
"url": "https://github.com/coreui/coreui-free-react-admin-template/issues"
我们尝试了不同的插件,但没有成功。 变换对象休息传播 出现运行时错误。 我们必须动态更新按钮属性,并且传播运算符是唯一的选择。
【问题讨论】:
你在使用 create react 应用吗?您还可以显示更多导致错误的代码 向我们展示该组件的更多代码。 我们正在使用 react 脚本 这个错误似乎与传播语法无关,而是this
关键字
这在范围内具有价值。我也检查过了
【参考方案1】:
你需要为此安装 babel 插件。我没有安装preset-es2015,而是安装了 babel-preset-env ,它可以作为 (es2015, es2016, es2017) 一起使用。
如果是the plugin,您需要的扩展运算符。
【讨论】:
试过..但没有运气 "devDependencies": "babel-jest": "^23.0.1", "babel-plugin-transform-object-rest-spread": "^6.26. 0”、“node-sass-chokidar”:“^1.3.0”、“npm-run-all”:“^4.1.3”、“react-scripts”:“^1.1.4”、“babel” : "plugins": [ "transform-object-rest-spread" ] , 您能分享错误的图像吗?这样我就可以获得有关该错误的更多信息。 更新问题以上是关于传播运算符不工作 ...this.state.attributes的主要内容,如果未能解决你的问题,请参考以下文章
不传播的原因是啥(es 6传播运算符)javascript错误对象[重复]
为啥 C# 6.0 在使用 Null 传播运算符时不允许设置非 null 可空结构的属性?