mirror of
https://github.com/201206030/novel-front-web.git
synced 2025-04-27 07:50:50 +00:00
fix: 通过请求拦截来添加 Authorization Header
This commit is contained in:
parent
a23a48eaf8
commit
9ae00b0902
@ -8,9 +8,8 @@
|
||||
><a href="/">网站首页</a><i class="line">|</i
|
||||
><a href="/about/default.html">关于我们</a><i class="line">|</i
|
||||
><a href="/about/contact.html">联系我们</a><i class="line">|</i
|
||||
><router-link :to="{ name: 'feadBack' }" class="line" >反馈留言</router-link><i class="line">|</i
|
||||
><a href="/author/index.html">作家专区</a><i class="line">|</i
|
||||
><a href="/mobile/fiction_house.apk">客户端</a>
|
||||
><a href="javascript:void(0)" @click="goFeedBack">反馈留言</a><i class="line">|</i><a href="/author/index.html">作家专区</a
|
||||
><i class="line">|</i><a href="/mobile/fiction_house.apk">客户端</a>
|
||||
</li>
|
||||
<li>
|
||||
Copyright (C) xiongxyang.gitee.io All rights
|
||||
@ -23,8 +22,23 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useRouter } from "vue-router";
|
||||
import { getToken } from "@/utils/auth";
|
||||
export default {
|
||||
name: "Footer"
|
||||
name: "Footer",
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const goFeedBack = () => {
|
||||
if(!getToken()){
|
||||
router.push({name: 'login'});
|
||||
}else{
|
||||
router.push({name: 'feadBack'});
|
||||
}
|
||||
};
|
||||
return {
|
||||
goFeedBack
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
</script>
|
@ -1,7 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import router from '@/router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {getToken,removeToken, setToken} from '@/utils/auth'
|
||||
import {getToken,removeToken,removeNickName, setToken} from '@/utils/auth'
|
||||
|
||||
|
||||
|
||||
@ -9,9 +9,16 @@ axios.defaults.baseURL = process.env.VUE_APP_BASE_API_URL
|
||||
axios.defaults.timeout = 10000
|
||||
axios.defaults.withCredentials = true
|
||||
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
|
||||
axios.defaults.headers['Authorization'] = getToken() || ''
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/json'
|
||||
|
||||
axios.interceptors.request.use(config => {
|
||||
config.headers['Authorization'] = getToken()
|
||||
return config
|
||||
}, error => {
|
||||
console.log(error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
|
||||
axios.interceptors.response.use(res => {
|
||||
if (typeof res.data !== 'object') {
|
||||
ElMessage.error('服务端异常!')
|
||||
@ -25,6 +32,7 @@ axios.interceptors.response.use(res => {
|
||||
if (res.data.code == 'A0230') {
|
||||
// 移除 token
|
||||
removeToken();
|
||||
removeNickName();
|
||||
router.push({ path: '/login' })
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user