Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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 尝试使用mongodb创建登录名_Javascript_Html_Vue.js_Authentication - Fatal编程技术网

Javascript 尝试使用mongodb创建登录名

Javascript 尝试使用mongodb创建登录名,javascript,html,vue.js,authentication,Javascript,Html,Vue.js,Authentication,我试图检查用户在登录表单中输入的详细信息与mongodb数据中的匹配情况,例如电子邮件和密码。但此功能不起作用。当用户输入正确的信息时,应将其引导至主页 const logindetails = new Vue({ el: '#logindetails', data: { errors: [], email: "", passwordInput: "" }, methods: { login: function () { var ac

我试图检查用户在登录表单中输入的详细信息与mongodb数据中的匹配情况,例如电子邮件和密码。但此功能不起作用。当用户输入正确的信息时,应将其引导至主页

const logindetails = new Vue({
  el: '#logindetails',
  data: {
    errors: [],
    email: "",
    passwordInput: ""
  },

  methods: {
    login: function () {
      var account = db.collection('users')(userdetails.email === userdetails.email &&
        userdetails.passwordInput === userdetails.password) ? userdetails : null;
    });

if (account) {
  window.location.href = "welcomepage.html?email=" + account.email;
} else {
  alert("Email/Password has not been identified.");
     }
   }
  }
 });


在尝试重新格式化您的问题以删除HTML时,我注意到您有几个不匹配的括号

您有一个额外的行(代码>)阻止您的
登录
函数访问
if
语句

正确的缩进可以帮助您发现这样的错误

以下是删除该行后的更正代码

const logindetails = new Vue({
  el: '#logindetails',
  data: {
    errors: [],
    email: "",
    passwordInput: ""
  },

  methods: {
    login: function () {
      var account = db.collection('users')(userdetails.email === userdetails.email &&
        userdetails.passwordInput === userdetails.password) ? userdetails : null;
      if (account) {
        window.location.href = "welcomepage.html?email=" + account.email;
      } else {
        alert("Email/Password has not been identified.");
      }
    }
  }
});
这是原始代码,在问题行旁边有一条注释

const logindetails = new Vue({
  el: '#logindetails',
  data: {
    errors: [],
    email: "",
    passwordInput: ""
  },

  methods: {
    login: function () {
      var account = db.collection('users')(userdetails.email === userdetails.email &&
        userdetails.passwordInput === userdetails.password) ? userdetails : null;
    });  //<-- looks wrong, stops 'login' function


if (account) {
  window.location.href = "welcomepage.html?email=" + account.email;
} else {
  alert("Email/Password has not been identified.");
}
    }
}
});
const logindetails=new Vue({
el:“#登录详细信息”,
数据:{
错误:[],
电邮:“,
密码输入:“
},
方法:{
登录:函数(){
var account=db.collection('users')(userdetails.email===userdetails.email&&
userdetails.passwordInput==userdetails.password)?userdetails:null;

});//请解释函数不起作用的原因。是否有错误?是否无法重定向用户?此外,请显示您迄今为止所做的尝试,这可能会为其他人节省一些工作。您是否尝试过调试代码?谢谢您的回复。它只是说“电子邮件未识别”?我在控制台中看不到错误。我编写的代码上面是我到目前为止尝试过的。这是完整的代码吗?因为括号和括号不匹配。这可能是导致问题的原因。如果您正确设置代码格式以便更容易查看,If会有所帮助。这是完整的代码。哦,好的。谢谢您的帮助。我认为登录函数b有问题因为我试图检查详细信息是否与mongodb中的详细信息匹配。但它似乎不正确。@JananiAshok重新检查上面的答案,我重写了答案,因此答案可能更明显。您的
登录
函数没有达到
if
语句。我希望我解释得很好。用固定值替换您的代码我的答案顶部的版本应该可以解决您的问题。不要忘记更新有用的答案,并接受任何可以解决您问题的答案。感谢您的帮助,但它仍然没有执行if语句,我不知道问题在哪里。@JananiAshok加载调试程序,并在
login
函数顶部放置断点。检查它是否被执行。如果是,请逐行检查问题所在。如果我在chrome上测试它,我该如何做?我需要继续“源代码”吗?