File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ import { Loading } from 'element-ui'
2323
2424export default {
2525 name: " LoginPage" ,
26- data : function () {
26+ data : () => {
2727 return {
2828 form: {
2929 CnName: ' 大佬你好' ,
@@ -87,7 +87,22 @@ export default {
8787 }
8888 }).catch (function (error ) {
8989 });
90+ },
91+ // 监听enter键
92+ enterKey : function (){
93+ let that = this ;
94+ const code = event .keyCode ? event .keyCode : (event .which ? event .which : event .charCode );
95+
96+ if (code == 13 ) that .OnLogin ();
9097 }
98+ },
99+ // 生命周期不能使用箭头函数
100+ mounted : function (){
101+ document .addEventListener (' keyup' ,this .enterKey );
102+ },
103+ // 本组件销毁时注意移除监听,否则其他页面点击enter也会登陆
104+ destroyed : function (){
105+ document .removeEventListener (' keyup' , this .enterKey );
91106 }
92107}
93108 </script >
You can’t perform that action at this time.
0 commit comments