简体   繁体   English

我可以访问我在不同 js 文件中的 js 文件中声明的变量吗

[英]Can I access a variable I declared in a js file in different js file

I'm trying to export this js file.我正在尝试导出这个 js 文件。

const student =
{
    studentID : 1,
}
export {student}

this is my second file in which I'm trying to import it.这是我尝试导入的第二个文件。

import {student} from "./studentId";
console.log(student);

It's not importing it and throwing this error .它没有导入它并抛出此错误

Failed to load resource: the server responded with a status of 404 ()

Look at the error message.查看错误消息。 You are getting a 404 Not Found error.您收到 404 Not Found 错误。

Node.js does not need a file extension when loading a module. Node.js 在加载模块时不需要文件扩展名。 It has access to the file system and can look at all the files in a directory.它可以访问文件系统并且可以查看目录中的所有文件。

Web browsers do not have any way of telling if the URL you specified should have a .js or .jsx or .mjs or .tsx or whatever extension added to it. Web 浏览器无法判断您指定的 URL 是否应该具有.js.jsx.mjs.tsx或添加的任何扩展名。

You need to specify the actual URL you are importing.您需要指定要导入的实际 URL

 import {student} from "./studentId.js";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在页面上我声明了一个js变量,include js文件似乎无法访问它? - On page I declared a js variable, include js file can't seem to access it? 如何在我的node.js控制台中的javascript文件中声明一个变量? - How can I access a variable declared in a javascript file in my node.js console? 如何使用php文件中的GET获取在.js文件中声明的变量? - How can I use a GET from my php file, to get a variable that I declared in my .js file? 如何使用AngularJS访问其他js文件中的变量数据 - How can I access a variable data which is in a different js file using AngularJS React - 如何访问不同 .js 文件中的一个 .js 文件中的状态/数组? - React - How can I access a state/array that's in one .js file in a different .js file? 如何在Jquery中访问变量并在另一个外部.js文件中使用它的值? 变量为$ generationP - How can I access a variable in Jquery and use its value in another external .js file ? The variable is $generatedP 如何访问用户对象在不同的​​js文件 - How do I access the user object in a different js file 如何在 vue js 中使用内联声明的变量? - how can i use variable declared inline in vue js? 我可以从 JS 中的另一个文件中逐个导入特定变量吗? - Can I import specific variable by variable from another file in JS? 如何在JQUERY中访问不同js文件中的函数? - How can I access the function which inside different js file in JQUERY?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM