简体   繁体   English

如何在 javascript 上的另一个 js 文件中从 function 获取返回数据

[英]How to get return data from function in another js file on javascript

How can i retrieve a return data in another file js?如何在另一个文件 js 中检索返回数据?

this is my user.js looks like这是我的 user.js 看起来像

export default function getUser() {
    const data = localStorage.getItem("user-account")
    //console.log(data.user.ID)
    const user = {
        ID: data.user.ID,
        Name: data.user.Name, 
    }
  return user;
}

and i want to import them and get the return user in another file js, because i want to use this file as global function any solution?我想导入它们并在另一个文件 js 中获取返回用户,因为我想将此文件用作全局 function 任何解决方案?

Try importing it into another file and logging the result.尝试将其导入另一个文件并记录结果。

import getUser from './user'

console.log(getUser())

Take note that you need a script type of 'module' for this to work请注意,您需要一个脚本类型的“模块”才能工作

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

相关问题 如何将get函数中的数据从node.js中的同一个js文件中的另一个函数中获取? - How can I get data from a get function to another function in the same js file in node.js? 如何使用参数从 js 文件调用 javascript 函数并从 tsx 文件返回数据? - How to Call javascript function from js file with parameter and return data from tsx file? 如何从另一个JavaScript文件中的另一个函数读取返回值 - How to read a return value from another function in another javascript file 如何将使用 .get() 从 firestore 获取的文档数据返回到 JS 中的另一个函数 - How to return the document data got from firestore using .get() to another function in JS 如何从节点js中的另一个文件调用javascript class function? - how to call a javascript class function from a another file in node js? 如何从另一个JS文件调用Javascript function - How to call Javascript function from another JS file 如何从 js 文件上的一个 function 获取变量并将其用于另一个 js 文件上的另一个 function? - How do I get a variable from one function on a js file and use it for another function on another js file? Javascript-从另一个js文件调用函数 - Javascript - call function from another js file 从另一个js文件调用javascript函数 - Call javascript function from another js file 从另一个.js文件调用javascript函数 - Calling a javascript function from another .js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM