ES6 export,import报错
问题描述:
现有两个文件:
profile.js
const firstName = 'Michael';
const lastName = 'Jackson';
const year = 2018;
export {firstName, lastName, year}
test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
import {firstName, lastName, year} from './profile.js';
console.log(firstName);
console.log(lastName);
console.log(year);
</script>
</body>
</html>
运行结果:

test.html:9 Uncaught SyntaxError: Unexpected token {
问题解答:
在HTML文件中不能使用export,import,需要在webpack构建项目中使用,并且只作用于.vue和.js文件。
如果非要使用且浏览器支持ES6,需要加上 type="module"。
<script type="module">
import {firstName, lastName, year} from './profile.js';
console.log(firstName);
console.log(lastName);
console.log(year);
</script>
ES6 export,import报错的更多相关文章
- 用js中的let等操作,要手动开启ECMAScript6(如果不设置,let等ES6语法会报错)
问题:idea默认没有开启ECMAScript6,需要进行设置:(如果不设置,let等ES6语法会报错)步骤: File | Settings | Languages & Frameworks ...
- es6 import 报错
现在绝大多数的浏览器都不支持ES6,所以使用es6时需要使用bebal把es6转化为es5, 项目目录: demo1:单个js文件的转化 src文件下的 test1.js const aa=" ...
- es6编写generator报错
首先babel基础包(不安装额外东西)并不是支持完整的es6语言 自己写的如下代码 let generator = function* () { ; ,,]; ; }; var gen = gener ...
- vue +ts 在router的路由中import报错的解决方案
在router.ts中引入.vue文件,会提示打不到module,但是编译可能成功,运行也不报错 找了好久,发现了这个答案 https://segmentfault.com/a/11900000167 ...
- 关于使用spring版本4.1.6注解@Import报错
记录一下遇到的错误 org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 使用环境:spring 4.1. ...
- matplotlib.pyplot import报错: ValueError: _getfullpathname: embedded null character in path
Environment: Windows 10, Anaconda 3.6 matplotlib 2.0 import matplotlib.pyplot 报错: ValueError: _getfu ...
- Eclipse + Pydev开发Python时import报错解决方法
一. 原文链接:http://blog.csdn.net/lhanchao/article/details/51306626 用eclipse +PyDev开发python时, ...
- ImportError: DLL load failed: 找不到指定的模块;ImportError: numpy.core.multiarray failed to import 报错解决
python程序运行出错,出错的两行主要信息如下: ImportError: DLL load failed: 找不到指定的模块 ImportError: numpy.core.multiarray ...
- Windows下通过pip安装PyTorch 0.4.0 import报错
问题:通过pip安装PyTorch 0.4.0成功,但是import时报错. import torch File "D:\Python\Python36\lib\site-packages ...
随机推荐
- Python-time和datetime模块
一.time模块 1.表示时间的三种方式 >>> import time >>> time.time() #当前时间戳 1509525556.8485825 > ...
- Restframework的版本及分页
1.版本 1.1基于url的get传参方式 1.创建django项目(起名我的是version),再创建一个app01应用 创建完成,通过python3 manage.py startapp api ...
- 零基础Python知识点回顾(二)
开始了,继续说!字符串替换,就是预留着空间,后边再定义要填上什么,这种叫字符串格式化,其有两种方法: % 和 format %s 就是一个占位符,这个占位符可以被其它的字符串代替 >&g ...
- 動態SQL運用實例
動態SQL運用實例 語法8.1.6之前: EXECUTE IMMEDIATE dynamic_sql_string [INTO {define_var1 [, define_var2] ... | p ...
- js bind的实现
call,apply,bind都是用来挟持对象或者说更改this指向的,但是区别还是有的,call 传参是 fn.call(this,1,2,3) apply传参是 fn.apply(this,[1, ...
- 仿LordPE获取PE结构
乍一看LordPE一个小工具一般般,真的动手做起来才知道技术含量高的很. 当前只是获取到PE结构并打印,仅此而已. PE.h #pragma once #include <stdio.h> ...
- poj 1236 Network of Schools : 求需要添加多少条边成为强连通图 tarjan O(E)
/** problem: http://poj.org/problem?id=1236 缩点后入度为0的点的总数为需要发放软件的学校个数 缩点后出度为0的点的总数和入度为0的点的总数的最大值为需要增加 ...
- Percona-Tookit工具包之pt-online-schema-change
Preface As we all know,it's really a troublesome thing to DBA in scenario of changing table ...
- 关于api接口
前阵子一直疯狂的找关于php的api接口方面的资料来学习,总结了一下,无非就是请求数据,然后返回数据,当然也要设置相关安全措施,比如认证口令 等.返回数据格式是json 还是xml 看自己需求咯
- Mysql基础3-数据操作语言DML-数据查询语言DQL
主要: 数据操作语言DML 数据查询语言DQL 数据操作语言DML DML: Data Mutipulation Language 插入数据(增) 一般插入数据形式 1)形式1: insert [in ...