我使用 vue-authenticate (https://github.com/dgrubelic/vue-authenticate)以ID /密码和Oauth 1和2登录 .
我把路由器重定向到仪表板页面上的用户重定向的地方?
this.$router.push({name: 'dashboard'})
My code store.js with Vuex:
import Vue from 'vue'
import Vuex from 'vuex'
import {vueAuth} from './auth'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
isAuthenticated: false
},
getters: {
isAuthenticated () {
return vueAuth.isAuthenticated()
}
},
mutations: {
isAuthenticated (state, payload) {
state.isAuthenticated = payload.isAuthenticated
},
setProfile (state, payload) {
state.profile = payload.profile
}
},
actions: {
login (context, payload) {
payload = payload || {}
return vueAuth.login(payload.user, payload.requestOptions).then((response) => {
context.commit('isAuthenticated', {
isAuthenticated: vueAuth.isAuthenticated()
})
})
}
}
})
1 回答
在vue组件中调度操作后,可以使用.then(),在完成调度操作后可以使用$ router.push()方法 .
或者您可以在actions.js文件中使用,但我正在使用vue中的$ router作业