[英]Export array as an es6 module
由於某種原因,我無法使用導出為es6模塊的數組:
export const choices = [
['first', 'First'],
['second', 'Second'],
['third', 'Third'],
]
然后:
import { choices } from './constants'
console.log(choices) // undefined
如果我只是在我嘗試使用它的同一個文件中聲明const
,它會按預期工作。
瀏覽器上下文中的模塊使用相對URL,包括擴展名。 所以導入應該from './constants.js'
而不僅僅是from './constants'
。 (后者在Node.js上會很好,但目前實驗模塊支持。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.