Add setToken in VueX and call it from SigninForm
This commit is contained in:
parent
a92a0d1c7e
commit
1363ad489e
@ -38,6 +38,7 @@
|
||||
|
||||
<script>
|
||||
import Api from '@/api'
|
||||
import {mapMutations} from "vuex";
|
||||
|
||||
export default {
|
||||
name: "SignupForm",
|
||||
@ -52,6 +53,8 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(['setToken']),
|
||||
|
||||
signin() {
|
||||
this.error = false
|
||||
this.invalid = false
|
||||
@ -60,8 +63,11 @@
|
||||
username: this.form.username,
|
||||
password: this.form.password
|
||||
})
|
||||
.then(response => console.log(response.data))
|
||||
.then(response => {
|
||||
this.setToken({token: response.data.token})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
if (error.response && error.response.status === 401)
|
||||
this.invalid = true
|
||||
else
|
||||
|
||||
@ -4,12 +4,13 @@ import Vuex from 'vuex'
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
},
|
||||
mutations: {
|
||||
},
|
||||
actions: {
|
||||
},
|
||||
modules: {
|
||||
}
|
||||
state: {
|
||||
token: ''
|
||||
},
|
||||
mutations: {
|
||||
setToken: (state, {token}) => {
|
||||
state.token = token;
|
||||
}
|
||||
},
|
||||
actions: {}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user