使用辅助函数 mapActions

This commit is contained in:
jqtmviyu@gmail.com 2021-01-15 16:13:56 +08:00
parent 67073c5e86
commit 7084b08dc9

View File

@ -57,6 +57,7 @@
<script>
import { validMobile } from '@/utils/validate'
import { mapActions } from 'vuex'
export default {
name: 'Login',
@ -114,6 +115,7 @@ export default {
}
},
methods: {
...mapActions(['user/login']),
showPwd() {
if (this.passwordType === 'password') {
this.passwordType = ''
@ -127,7 +129,10 @@ export default {
async handleLogin() {
try {
await this.$refs.loginForm.validate() //
await this.$store.dispatch('user/login', this.loginForm) // await
// await this.$store.dispatch('user/login', this.loginForm) // await
// 使 mapActions methods store.dispatch
await this['user/login'](this.loginForm)
this.$router.push('/')
} catch (error) {
console.log('捕获错误')
console.log(error)