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

处理token过期

parent 10f59b59
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
<div class="more t1 list-con" >更多 ></div> <div class="more t1 list-con" >更多 ></div>
</div> </div>
<ul> <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> <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> </li>
</ul> </ul>
</div> </div>
...@@ -56,12 +56,6 @@ ...@@ -56,12 +56,6 @@
import {getLoopPic} from '@/common/list.js' import {getLoopPic} from '@/common/list.js'
import {getSecond,getCategoryList,getListSite} from '@/common/list.js' import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
export default { export default {
/* computed:{
//取出特定的三项值
dynamicList(){
return this.dynamicList.slice(3,3)
}
}, */
created(){ created(){
this.getLoopPic() this.getLoopPic()
this.getSecond() this.getSecond()
...@@ -72,14 +66,15 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js' ...@@ -72,14 +66,15 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
async getCategoryList(){ async getCategoryList(){
const {data} = await getCategoryList() const {data} = await getCategoryList()
this.dynamicList = data this.dynamicList = data
console.log(data,'-------------') this.content = data//把数据存在content中
this.id = this.content.id
}, },
async getListSite(){ async getListSite(){
let message = {} let message = {}
message.cateId = this.id message.cateId = this.id
const {data} = await getListSite(message) const {data} = await getListSite()
console.log(data,'++++++++++++++++++++++++') console.log(data,'++++++++++++++++++++++++')
this.dynamicList.list = data /* this.dynamicList.list = data.list */
}, },
//添加验证方法 //添加验证方法
async getSecond(){ async getSecond(){
...@@ -88,15 +83,14 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js' ...@@ -88,15 +83,14 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
this.showDefault = false this.showDefault = false
const {data,code} = await getSecond() const {data,code} = await getSecond()
//code为401,失效 清空并返回至登录页 //code为401,失效 清空并返回至登录页
if(code ==401){ console.log(code)
/* if(code == 401){
window.sessionStorage.clear() window.sessionStorage.clear()
this.$router.push("/login/user") this.$router.push("/login/user")
} } */
window.sessionStorage.setItem("companyName",data.companyName) window.sessionStorage.setItem("companyName",data.companyName)
this.userName = window.sessionStorage.getItem("companyName") this.userName = window.sessionStorage.getItem("companyName")
} }
/* const {data} = await getSecond()
console.log(data) */
}, },
loginuser(){ loginuser(){
this.$router.push("/login/user") this.$router.push("/login/user")
...@@ -119,6 +113,8 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js' ...@@ -119,6 +113,8 @@ import {getSecond,getCategoryList,getListSite} from '@/common/list.js'
}, },
data() { data() {
return { return {
content:[],
id:0,
dyname:[], dyname:[],
showDefault:true, showDefault:true,
userName:'Hi~欢迎来到捷安彩', userName:'Hi~欢迎来到捷安彩',
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
:current-page="currentPage" :current-page="currentPage"
:size ="size" :size ="size"
layout="total, prev, pager, next, jumper" layout="total, prev, pager, next, jumper"
:total="total" :total="total">
class="pageObj">
</el-pagination > </el-pagination >
</div> </div>
</ul> </ul>
......
import axios from 'axios' import axios from 'axios'
import { Message } from 'element-ui';
// import { Message, MessageBox } from 'element-ui' // import { Message, MessageBox } from 'element-ui'
// import store from '../store' // import store from '../store'
// import { getToken,get } from '@/utils/auth' // import { getToken,get } from '@/utils/auth'
...@@ -45,6 +46,13 @@ service.interceptors.response.use( ...@@ -45,6 +46,13 @@ service.interceptors.response.use(
* code为非200是抛错 可结合自己业务进行修改 * code为非200是抛错 可结合自己业务进行修改
*/ */
const res = response 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) { // if (res.code !== 200 && !res.access_token) {
// console.log(res) // console.log(res)
// Message({ // Message({
...@@ -67,6 +75,7 @@ service.interceptors.response.use( ...@@ -67,6 +75,7 @@ service.interceptors.response.use(
// } // }
// return Promise.reject('error') // return Promise.reject('error')
// } // }
if (res.status == 200) { if (res.status == 200) {
return res.data return res.data
} else { } else {
...@@ -75,6 +84,13 @@ service.interceptors.response.use( ...@@ -75,6 +84,13 @@ service.interceptors.response.use(
}, },
error => { error => {
console.log(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({
// message: error.message, // message: error.message,
// type: 'error', // 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