url加token
This commit is contained in:
parent
ff65d38c73
commit
91ceaa2227
@ -2,7 +2,7 @@ import axios, { AxiosInstance } from 'axios';
|
||||
import { AxiosError } from 'axios';
|
||||
import { Dialog } from 'quasar';
|
||||
import { boot } from 'quasar/wrappers';
|
||||
//import { getJwtToken } from 'src/configs/TokenManage';
|
||||
import { getJwtToken } from 'src/configs/TokenManage';
|
||||
import { getHttpBase } from 'src/configs/UrlManage';
|
||||
|
||||
declare module '@vue/runtime-core' {
|
||||
@ -76,9 +76,9 @@ export default boot(({ app, router }) => {
|
||||
// 拦截请求,添加
|
||||
api.interceptors.request.use(
|
||||
(config) => {
|
||||
//config.headers.Authorization = getJwtToken();
|
||||
config.headers.Authorization = 'Bearer 1e2d0d5d96034f4a0805af6512051ddc';
|
||||
config.headers['Token'] = '1e2d0d5d96034f4a0805af6512051ddc';
|
||||
const token = getJwtToken();
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
config.headers['Token'] = token;
|
||||
config.cancelToken = source.token;
|
||||
if (isOpenDialog) {
|
||||
source.cancel();
|
||||
|
@ -1,7 +1,7 @@
|
||||
const JwtTokenKey = 'jwttoken';
|
||||
|
||||
export function saveJwtToken(token: string) {
|
||||
sessionStorage.setItem(JwtTokenKey, `Bearer ${token}`);
|
||||
sessionStorage.setItem(JwtTokenKey, token);
|
||||
}
|
||||
|
||||
export function getJwtToken(): string | null {
|
||||
|
@ -121,16 +121,21 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import SysMenu from 'src/components/SysMenu.vue';
|
||||
// import { useRouter } from 'vue-router';
|
||||
import { clearJwtToken } from 'src/configs/TokenManage';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { clearJwtToken, saveJwtToken } from 'src/configs/TokenManage';
|
||||
import { Dialog } from 'quasar';
|
||||
|
||||
// const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
onMounted(() => {
|
||||
if (route.params.token) {
|
||||
saveJwtToken(route.params.token as string);
|
||||
}
|
||||
});
|
||||
|
||||
const leftDrawerOpen = ref(false);
|
||||
|
||||
function toggleLeftDrawer() {
|
||||
leftDrawerOpen.value = !leftDrawerOpen.value;
|
||||
onResize();
|
||||
|
@ -3,13 +3,13 @@ import { RouteRecordRaw } from 'vue-router';
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/home',
|
||||
redirect: '/home/1e2d0d5d96034f4a0805af6512051ddc',
|
||||
meta: {
|
||||
hidden: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/home',
|
||||
path: '/home/:token',
|
||||
component: () => import('layouts/MainLayout.vue'),
|
||||
meta: {
|
||||
hidden: true,
|
||||
|
Loading…
Reference in New Issue
Block a user