【问题标题】:const arrow function can't access importsconst 箭头函数无法访问导入
【发布时间】:2017-08-22 18:06:30
【问题描述】:

为什么跳板函数中没有定义User?
springboard 在 React 路由路由中被称为 onEnter

import User from '/imports/api/user.js';

const springboard = (nextState, replace, callback) => {
    console.log(User.get());
}

来自用户的片段:

User = {
  get: function() {
    return Meteor.user() || {};
  },
  …
}

【问题讨论】:

    标签: meteor reactjs react-router


    【解决方案1】:

    您必须导出要导入的对象:

    export default {
      get: …
    

    请注意,导出对象的名称无关紧要。导入时可以给它起任何名字,例如User

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-20
      • 2019-10-27
      相关资源
      最近更新 更多