[英]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.