Commit 76a0fb3c authored by 吴冠's avatar 吴冠

处理token过期

parent 10f59b59
......@@ -34,9 +34,9 @@
<div class="more t1 list-con" >更多 ></div>
</div>
<ul>
<li v-for="(item,index) in dynamicList.list" :key="index" v-if="index<5" class="flex-between list-con">
<li v-for="(item,index) in dynamicList" :key="index" v-if="index<5" class="flex-between list-con">
<nuxt-link tag="div" to="#">{{item.title}}</nuxt-link>
<div class="time">{{item.createTime.slice(5,10)}}</div>
<div class="time">{{item.createTime}}</div>
</li>
</ul>
</div>
......@@ -56,12 +56,6 @@
import {getLoopPic} from '@/common/list.js'
import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
export default {
/* computed:{
//取出特定的三项值
dynamicList(){
return this.dynamicList.slice(3,3)
}
}, */
created(){
this.getLoopPic()
this.getSecond()
......@@ -72,14 +66,15 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
async getCategoryList(){
const {data} = await getCategoryList()
this.dynamicList = data
console.log(data,'-------------')
this.content = data//把数据存在content中
this.id = this.content.id
},
async getListSite(){
let message = {}
message.cateId = this.id
const {data} = await getListSite(message)
const {data} = await getListSite()
console.log(data,'++++++++++++++++++++++++')
this.dynamicList.list = data
/* this.dynamicList.list = data.list */
},
//添加验证方法
async getSecond(){
......@@ -88,15 +83,14 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
this.showDefault = false
const {data,code} = await getSecond()
//code为401,失效 清空并返回至登录页
if(code ==401){
console.log(code)
/* if(code == 401){
window.sessionStorage.clear()
this.$router.push("/login/user")
}
} */
window.sessionStorage.setItem("companyName",data.companyName)
this.userName = window.sessionStorage.getItem("companyName")
}
/* const {data} = await getSecond()
console.log(data) */
},
loginuser(){
this.$router.push("/login/user")
......@@ -119,6 +113,8 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
},
data() {
return {
content:[],
id:0,
dyname:[],
showDefault:true,
userName:'Hi~欢迎来到捷安彩',
......
......@@ -26,8 +26,7 @@
:current-page="currentPage"
:size ="size"
layout="total, prev, pager, next, jumper"
:total="total"
class="pageObj">
:total="total">
</el-pagination >
</div>
</ul>
......
import axios from 'axios'
import { Message } from 'element-ui';
// import { Message, MessageBox } from 'element-ui'
// import store from '../store'
// import { getToken,get } from '@/utils/auth'
......@@ -45,6 +46,13 @@ service.interceptors.response.use(
* code为非200是抛错 可结合自己业务进行修改
*/
const res = response
/* if (res.code == 401) {
window.sessionStorage.removeItem('token');
this.$router.push("/login/user")
}else {
return res.data
} */
// if (res.code !== 200 && !res.access_token) {
// console.log(res)
// Message({
......@@ -67,6 +75,7 @@ service.interceptors.response.use(
// }
// return Promise.reject('error')
// }
if (res.status == 200) {
return res.data
} else {
......@@ -75,6 +84,13 @@ service.interceptors.response.use(
},
error => {
console.log(error)
if(error.response.status == 401){
sessionStorage.removeItem('token')
Message.error("登录失效,请重新登录")
setTimeout(function(){
location.href = 'http://localhost:3000/login/user/'
},2000)
}
// Message({
// message: error.message,
// type: 'error',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment