鍍金池/ 問(wèn)答/HTML/ 使用對(duì)象運(yùn)算擴(kuò)展符報(bào)錯(cuò)

使用對(duì)象運(yùn)算擴(kuò)展符報(bào)錯(cuò)

我有一個(gè)config.js文件:

const serviceModule = {
  AxiosConfig:{
    baseURL: 'http://10.10.10.105:8001/',

    withCredentials: true,
    headers: {

      "Content-Type": "application/json;charset=utf-8"

    }
  }
}



let ApiSetting = {...serviceModule };

export default ApiSetting

但是在npm run dev的時(shí)候會(huì)報(bào)錯(cuò):

ERROR in ./src/api/config.js
Module build failed: SyntaxError: Unexpected token (28:18)

  26 | 
  27 | 
> 28 | let ApiSetting = {...serviceModule };
     |                   ^
  29 | 
  30 | export default ApiSetting
  31 | 

 @ ./src/api/http.js 6:0-34
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main

請(qǐng)問(wèn)這是哪里的問(wèn)題呢?

回答
編輯回答
兔囡囡

...是ES2018 里面的特性,需要配置下babel的環(huán)境。

babelrc配置可以參照如下所示

{
  "presets": [
    ["env", { "modules": false }],
    "stage-2"
  ],
  "plugins": ["transform-runtime"],
  "comments": false,
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": [ "istanbul" ]
    }
  }
}
2018年6月17日 06:31
編輯回答
耍太極

The Rest/Spread Properties for ECMAScript proposal (stage 4) adds spread properties to object literals.

來(lái)源 MDN
2018年4月22日 05:54
編輯回答
乖乖瀦
2017年6月11日 09:20