【问题标题】:Why Method call inside onSubmit throws error?为什么 onSubmit 内部的方法调用会引发错误?
【发布时间】:2019-06-23 20:57:40
【问题描述】:

我尝试调用 metetor 方法,但它向我抛出错误“Uncaught TypeError: Meteor.call is not a function”,但是当我尝试在 imports/api/some.js 内的另一个文件中调用相同的方法时,这意味着调用代码是正确的,但它在 onSubmit 内部工作,为什么?这里是githuburl

文件:imports/ui/otp.js

onSubmit(e) {
  e.preventDefault();

  let otp = this.refs.otp.value.trim();

  Meteor.call('find-otp', otp, (error, result) => {
    if(error) {
      console.log('otp error check', error);
    } else {
      console.log('otp res check', result);
    }
   });
}

文件:imports/api/db.js

   Meteor.methods({
    'find-otp' (otp) {
        // if(!this.userId) {
        //     throw new Meteor.Error('not-authorized');
        //  }
         console.log('otpcheck', otp);
         return true;
        //  return otp; // also I try this
    }
});

【问题讨论】:

  • 你在导入Meteor吗?即:import { Meteor } from 'meteor/meteor'
  • thanx,我的愚蠢错误我忘记使用 {}。

标签: javascript reactjs meteor


【解决方案1】:

确保正确导入 Meteor:

import { Meteor } from 'meteor/meteor'

【讨论】:

    猜你喜欢
    • 2018-03-30
    • 1970-01-01
    • 2013-08-07
    • 2018-01-04
    • 1970-01-01
    • 2013-09-26
    • 2014-12-11
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多