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