【发布时间】:2017-08-26 17:51:21
【问题描述】:
我正在尝试从另一个模块导入一个函数,但在运行时出现错误:
TypeError: _this.getData is not a function.
数据.js
function getData() {
return [
{ id: 1,
name: 'Pluto',
type: 'Dwarf Planet'
},
{ id: 2,
name: 'Neptune',
type: 'Planet'
}
]
}
export { getData }
worker.js
import getData from data.js
this.data = this.getData()
然后在运行时出现上述浏览器错误。关于我做错了什么有什么想法吗?
【问题讨论】:
-
google -> "es6 import syntax" -> 1. 结果:MDN: import
-
反正是
getData,不是this。模块范围内没有this。
标签: javascript