从 Meteor 中的包文件夹结构导入文件

Import file from packages folder structure in Meteor

我似乎无法在我的包文件夹中使用导入语句。

我的文件结构如下:

-client
-model
  -users.js
-packages
  -mobile
  -browser
    -client
      -auth
        -login
          -login.component.js

在 login.component.js 我需要 import { user } from '/model/users.js'。这可能吗?如果是这样,我该怎么做?如果不是,什么是好的解决方法?

编辑:users.js

const User = Class.create({
  name: 'User',
  collection: Meteor.users,
  secured: true,
  fields: {
     username: {type: String },
     createdAt: { type: Date },
     userData: { type: UserData, optional:true },
    fullName: {
       type: String,
       resolve(doc) {
         if (doc && doc.userData)
           return doc.userData.firstName + ' ' + doc.userData.lastName;
         else {
           "no name"
         }
       }
     }
   }
 });
 export { User };

import 语句对于 /imports 文件夹中的文件是必需的。该文件夹之外的所有内容都会为您自动加载,因此您无需手动导入。

此处有更多详细信息:https://guide.meteor.com/structure.html#intro-to-import-export

只需确保您的 User 对象是全局对象,即更改

const User = Class.create({

User = Class.create({