为什么window.location.href不能在Vue.js中运行?

时间:2017-10-27 06:42:23

标签: javascript php html vue.js

 <script>
    logBox = new Vue({
    el: "#logBox",
    data: {
    email : '',
    password: ''
    },
    methods: {
      handelSubmit: function(e) {
           data = {};
           data['email'] = this.email;
           data['password'] = this.password;
            $.ajax({
              url: 'https://herokuapp.com/api/', //my url
              data: data,
              type: "POST",
              dataType: 'json',
              success: function(e) {
              if(e.status != false){
               alert("Login Success").then(function() {
            // Redirect the user
            window.location.href = "https://stackoverflow.com/";
            console.log('The Ok Button was clicked.');
            });
             }
              else {
                alert("failed to login!");
              }
          }
            });
            return false;
}
},
});

这是我的登录代码。成功登录后,我需要重定向到成功页面,但window.location.href无效,我无法直接进入新页面。那么,任何人都可以解决我的问题吗?

1 个答案:

答案 0 :(得分:0)

alert() 不是承诺。您应该将其修复为:

          if (e.status != false) {
            alert("Login Success");
            // Redirect the user
            window.location.href = "https://stackoverflow.com/";
          }