1***@qq.com
- 发布:2020-03-06 12:55
- 更新:2020-04-20 00:02
- 阅读:2481
1***@qq.com (作者)
uniRequest.interceptors.request.use(
function(request) {
if (!request.headers) {
request.headers = {};
}
if (request.method === 'post') {
console.log(request);
request.headers['Content-Type'] = 'application/json;charset=UTF-8';
}
request.headers['Cookie'] = uni.getStorageSync('cookie');
console.log('请求发送之前', request)
return request
},
function(error) {
console.log('请求发送之前失败', error)
return Promise.reject(error)
}
)
uniRequest.interceptors.response.use(
function(request) {
console.log('请求返回数据', request)
const {
header
} = request
if (header && header['Set-Cookie']) {
let cookie = header['Set-Cookie'].split(';')[0]
if (/^JSESSIONID=?/.test(cookie)) {
uni.setStorageSync('cookie', cookie)
}
}
if (request.data.ret == "99999") {
uni.removeStorageSync('userInfor');
store.commit('resetUserInfor');
// #ifdef APP-PLUS
uni.redirectTo({
url: '/pages/login_app/login_app.vue'
})
// #endif
// #ifdef H5
uni.redirectTo({
url: '/pages/login_app/login_app.vue'
})
// #endif
// #ifdef MP-WEIXIN
uni.redirectTo({
url: '/pages/user_login/user_login'
})
// #endif
}
return request
},
function(error) {
console.log('请求返回数据失败', error)
return Promise.reject(error)
}
)
1***@qq.com (作者)
现在后台是请求需带上cookie,这块这么处理呢
2020-03-06 15:06
1***@qq.com (作者)
h5中设置header cookie 设置不上
2020-03-06 15:06