Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么onSubmit内部的方法调用抛出错误?_Javascript_Reactjs_Meteor - Fatal编程技术网

Javascript 为什么onSubmit内部的方法调用抛出错误?

Javascript 为什么onSubmit内部的方法调用抛出错误?,javascript,reactjs,meteor,Javascript,Reactjs,Meteor,我尝试调用Meteter方法,但它向我抛出错误“UncaughtTypeError:Meteor.call不是一个函数”,但当我尝试在imports/api/some.js中的另一个文件中调用相同的方法时,这是可行的,这意味着调用代码是正确的,但它在Submit内部工作。为什么?这是github 文件:导入/ui/otp.js onSubmit(e) { e.preventDefault(); let otp = this.refs.otp.value.trim(); Meteo

我尝试调用Meteter方法,但它向我抛出错误“UncaughtTypeError:Meteor.call不是一个函数”,但当我尝试在imports/api/some.js中的另一个文件中调用相同的方法时,这是可行的,这意味着调用代码是正确的,但它在Submit内部工作。为什么?这是github

文件:导入/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);
    }
   });
}
   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
    }
});
文件:导入/api/db.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);
    }
   });
}
   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'

您正在导入流星吗?i、 e:
从'Meteor/Meteor'导入{Meteor}
thanx,我的愚蠢错误是我忘了使用{}。