我正在尝试从另一个模块导入一个函数,但运行时出现错误:
TypeError: _this.getData is not a function.
data.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()
然后我运行时出现了上述的浏览器错误。有什么想法是我做错了什么吗?
getData
,而不是this
。在模块范围内没有this
。 - Bergi