我尝试调用 metetor 方法,但它向我抛出错误“Uncaught TypeError: Meteor.call is not a function”但是当我尝试在 imports/api/some.js 中的另一个文件中调用相同方法时,这有效,这意味着调用代码是正确的,但它在 onSubmit 内部工作,为什么?这是 github url
文件: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'
关于javascript - 为什么 onSubmit 中的方法调用会抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56723147/