如何在Chrome / Firefox中导出ES6中的变量? [英] how export variable in ES6 in Chrome/Firefox?

查看:137
本文介绍了如何在Chrome / Firefox中导出ES6中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



index.js:

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

helper.js:

  export var bla = 20; 

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



< blockquote>

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


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


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


我也尝试跟随变体index.js:

 '使用严格'
import {bla} from'./helper.js';
console.log(bla);

我也尝试跟随变体index.js:



'pre> '使用'helper.js'的strict'
import {bla};
console.log(bla);

但错误信息保持不变。

解决方案

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



您需要某种预处理器或者透明的工作。


In latest versions of Firefox and Chrome, I try make export variable.

index.js:

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

helper.js:

export var bla = 20;

but Chrome console display follow error message:

Uncaught SyntaxError: Unexpected reserved word

firefox console display follow error message: SyntaxError: modules are not implemented yet

import { bla } from './helper'; <--

also I try follow variant index.js:

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

also I try follow variant index.js:

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

but the error message remains the same.

解决方案

This is not supported in Firefox and Chrome. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Browser_compatibility.

You'll need some kind of preprocessor or transpiler to make this work.

这篇关于如何在Chrome / Firefox中导出ES6中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆