Skip to content

Commit

Permalink
perf[Login]: optimize input focus interaction (#1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayunhai authored and PanJiaChen committed Mar 29, 2019
1 parent 20f6150 commit 96d3cfa
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<svg-icon icon-class="user" />
</span>
<el-input
ref="username"
v-model="loginForm.username"
:placeholder="$t('login.username')"
name="username"
Expand All @@ -26,6 +27,7 @@
<svg-icon icon-class="password" />
</span>
<el-input
ref="password"
v-model="loginForm.password"
:type="passwordType"
:placeholder="$t('login.password')"
Expand Down Expand Up @@ -96,7 +98,7 @@ export default {
return {
loginForm: {
username: 'admin',
password: '1111111'
password: '111111'
},
loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
Expand All @@ -119,6 +121,13 @@ export default {
created() {
// window.addEventListener('hashchange', this.afterQRScan)
},
mounted() {
if (this.loginForm.username === '') {
this.$refs.username.focus()
} else if (this.loginForm.password === '') {
this.$refs.password.focus()
}
},
destroyed() {
// window.removeEventListener('hashchange', this.afterQRScan)
},
Expand All @@ -129,6 +138,9 @@ export default {
} else {
this.passwordType = 'password'
}
this.$nextTick(() => {
this.$refs.password.focus()
})
},
handleLogin() {
this.$refs.loginForm.validate(valid => {
Expand Down

0 comments on commit 96d3cfa

Please sign in to comment.