Skip to content

Commit 96d3cfa

Browse files
mayunhaiPanJiaChen
authored andcommitted
perf[Login]: optimize input focus interaction (#1798)
1 parent 20f6150 commit 96d3cfa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/views/login/index.vue

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<svg-icon icon-class="user" />
1414
</span>
1515
<el-input
16+
ref="username"
1617
v-model="loginForm.username"
1718
:placeholder="$t('login.username')"
1819
name="username"
@@ -26,6 +27,7 @@
2627
<svg-icon icon-class="password" />
2728
</span>
2829
<el-input
30+
ref="password"
2931
v-model="loginForm.password"
3032
:type="passwordType"
3133
:placeholder="$t('login.password')"
@@ -96,7 +98,7 @@ export default {
9698
return {
9799
loginForm: {
98100
username: 'admin',
99-
password: '1111111'
101+
password: '111111'
100102
},
101103
loginRules: {
102104
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
@@ -119,6 +121,13 @@ export default {
119121
created() {
120122
// window.addEventListener('hashchange', this.afterQRScan)
121123
},
124+
mounted() {
125+
if (this.loginForm.username === '') {
126+
this.$refs.username.focus()
127+
} else if (this.loginForm.password === '') {
128+
this.$refs.password.focus()
129+
}
130+
},
122131
destroyed() {
123132
// window.removeEventListener('hashchange', this.afterQRScan)
124133
},
@@ -129,6 +138,9 @@ export default {
129138
} else {
130139
this.passwordType = 'password'
131140
}
141+
this.$nextTick(() => {
142+
this.$refs.password.focus()
143+
})
132144
},
133145
handleLogin() {
134146
this.$refs.loginForm.validate(valid => {

0 commit comments

Comments
 (0)