authRedirect.vue
993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script>
import { wxQrLogin } from '@/api/login'
import { getQueryValue } from '@/utils/index'
import { setToken } from '@/utils/auth'
export default {
components: {},
props: {},
data() {
return {}
},
watch: {},
computed: {},
async beforeCreate() {
// http://106.13.201.219/?auth_code=xxx#/authWehatCallback
// console.log('routerbeforeCreate', this.$route);
document.getElementById('loader-wrapper').classList.remove('loaded')
let auth_code = getQueryValue('code')
try {
let { data } = await wxQrLogin(auth_code)
setToken(data.access_token)
// 用以重置浏览器回调的url
history.replaceState({}, 'page', window.lwConfig.BASE_URL)
this.$router.replace('/')
// location.href = window.lwConfig.BASE_URL
} catch (error) {
document.getElementById('loader-wrapper').classList.add('loaded')
console.log(error)
}
},
mounted() {},
methods: {},
}
</script>
<template>
<div></div>
</template>