我正在尝试从'index.js'中的'test.js'导入函数
test.js:
var testFunction = function test(){ alert("hello World") }
export testFunction
在“ index.js”的最顶部,我尝试了以下语句:
import testFunction from './test.js'
现在,当我在浏览器中运行index.html文件时,我的firefox控制台出现以下错误:
SyntaxError:导入声明只能出现在模块的顶层(在第1行中)
var testFunction = function test(){ alert("hello World") }
export {testFunction}
index.js:import testFunction from './test.js'
//...
的HTML:<script type="module" src="./index.js">