Commit a522d09734844fffec1c7a4f65159bfb6226c2d3

Authored by Lawrence
1 parent c807572b

修复各页面按下回车键都会退回Contral页面的问题

Showing 1 changed file with 23 additions and 18 deletions
web_src/src/components/Login.vue
... ... @@ -29,14 +29,13 @@ export default {
29 29 }
30 30 },
31 31 created(){
32   - var that = this;
33   - document.onkeydown = function(e) {
34   - var key = window.event.keyCode;
35   - if (key == 13) {
36   - that.login();
  32 + var that = this;
  33 + document.onkeydown = function(e) {
  34 + var key = window.event.keyCode;
  35 + if (key == 13) {
  36 + that.login();
  37 + }
37 38 }
38   - }
39   -
40 39 },
41 40 methods:{
42 41  
... ... @@ -70,6 +69,7 @@ export default {
70 69 if (res.data == "success") {
71 70 that.$cookies.set("session", {"username": that.username}) ;
72 71 //登录成功后
  72 + that.cancelEnterkeyDefaultAction();
73 73 that.$router.push('/');
74 74 }else{
75 75 that.isLoging = false;
... ... @@ -84,18 +84,23 @@ export default {
84 84 that.$message.error(error.response.statusText);
85 85 that.isLoging = false;
86 86 });
87   -
88   -
89   -
90 87 },
91   - setCookie: function (cname, cvalue, exdays) {
92   - var d = new Date();
93   - d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
94   - var expires = "expires=" + d.toUTCString();
95   - console.info(cname + "=" + cvalue + "; " + expires);
96   - document.cookie = cname + "=" + cvalue + "; " + expires;
97   - console.info(document.cookie);
98   - },
  88 + setCookie: function (cname, cvalue, exdays) {
  89 + var d = new Date();
  90 + d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  91 + var expires = "expires=" + d.toUTCString();
  92 + console.info(cname + "=" + cvalue + "; " + expires);
  93 + document.cookie = cname + "=" + cvalue + "; " + expires;
  94 + console.info(document.cookie);
  95 + },
  96 + cancelEnterkeyDefaultAction: function() {
  97 + document.onkeydown = function(e) {
  98 + var key = window.event.keyCode;
  99 + if (key == 13) {
  100 + return false;
  101 + }
  102 + }
  103 + }
99 104 }
100 105 }
101 106 </script>
... ...