【问题标题】:how export variable in ES6 in Chrome/Firefox? [duplicate]如何在 Chrome/Firefox 中的 ES6 中导出变量? [复制]
【发布时间】:2015-12-31 05:49:32
【问题描述】:

在最新版本的 Firefox 和 Chrome 中,我尝试使用导出变量。

index.js:

'use strict'
import { bla } from './helper';
console.log(bla);

helper.js:

export var bla = 20;

但 Chrome 控制台显示以下错误消息:

未捕获的语法错误:意外的保留字

firefox 控制台显示以下错误消息: SyntaxError: 模块尚未实现

从 './helper' 导入 { bla };

我也尝试遵循变体 index.js:

'use strict'
import { bla } from './helper.js';
console.log(bla);

我也尝试遵循变体 index.js:

'use strict'
import { bla } from 'helper.js';
console.log(bla);

但错误信息保持不变。

【问题讨论】:

    标签: javascript google-chrome firefox ecmascript-6


    【解决方案1】:

    Firefox 和 Chrome 不支持此功能。见https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Browser_compatibility

    您需要某种预处理器或转译器来完成这项工作。

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 2016-03-28
      • 2017-06-29
      • 2017-06-03
      • 2012-04-06
      • 2016-09-20
      • 2018-04-06
      • 2016-04-23
      • 2018-04-21
      相关资源
      最近更新 更多