![](/img/trans.png)
[英]On page I declared a js variable, include js file can't seem to access it?
[英]Can I access a variable I declared in a js file in different js file
我正在嘗試導出這個 js 文件。
const student =
{
studentID : 1,
}
export {student}
這是我嘗試導入的第二個文件。
import {student} from "./studentId";
console.log(student);
它沒有導入它並拋出此錯誤。
Failed to load resource: the server responded with a status of 404 ()
查看錯誤消息。 您收到 404 Not Found 錯誤。
Node.js 在加載模塊時不需要文件擴展名。 它可以訪問文件系統並且可以查看目錄中的所有文件。
Web 瀏覽器無法判斷您指定的 URL 是否應該具有.js
或.jsx
或.mjs
或.tsx
或添加的任何擴展名。
您需要指定要導入的實際 URL 。
import {student} from "./studentId.js";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.