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