使用辅助函数 mapActions
This commit is contained in:
parent
67073c5e86
commit
7084b08dc9
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user