# just a flag
ENV = 'development'
# base api
VUE_APP_BASE_API = 'http://dev.api.watermarker-v1.moviebook.cn'
# just a flag
ENV = 'production'
# base api
VUE_APP_BASE_API = 'http://api.watermarker-v1.moviebook.cn'
// request interceptor service.interceptors.request.use( config => { // do something before request is sent // console.log(localStorage.getItem('LOCAL-TOKEN')) const localtoken = localStorage.getItem('LOCAL-TOKEN') if (localtoken) { // let each request carry token // ['X-Token'] is a custom headers key // please modify it according to the actual situation config.headers['AUTHORIZATION'] = 'Token ' + localtoken } return config }, error => { // do something with request error console.log(error) // for debug return Promise.reject(error) } )
// response interceptor service.interceptors.response.use( /** * If you want to get http information such as headers or status * Please return response => response */
/** * Determine the request status by custom code * Here is just an example * You can also judge the status by HTTP Status Code */ response => { const res = response.data if (res.status === 401 || res.status === 403) { // Message({ // message: res.msg, // type: 'error', // duration: 5 * 1000 // }) router.replace({ path: '/login' }) localStorage.removeItem('LOCAL-TOKEN') // to re-login // MessageBox.confirm('请重新登录', '', { // confirmButtonText: 'Re-Login', // cancelButtonText: 'Cancel', // type: 'warning' // }).then(() => { // store.dispatch('user/resetToken').then(() => { // location.reload() // }) // }) } return res // if the custom code is not 20000, it is judged as an error. // if (res.status !== 200) { // Message({ // message: res.msg || 'Error', // type: 'error', // duration: 5 * 1000 // })
// // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; // if (res.status === 401 || res.status === 403) { // // to re-login // // MessageBox.confirm('请重新登录', 'Confirm logout', { // // confirmButtonText: 'Re-Login', // // cancelButtonText: 'Cancel', // // type: 'warning' // // }).then(() => { // // store.dispatch('user/resetToken').then(() => { // // location.reload() // // }) // // }) // } // // return Promise.reject(new Error(res.message || 'Error')) // } else { // Message({ // message: res.msg || 'success', // type: 'success', // duration: 5 * 1000 // }) // return res // } }, error => { // Message({ // message: error.message, // type: 'error', // duration: 5 * 1000 // }) // router.replace({ // path: '/login' // }) return Promise.reject(error) } )
export default service
# just a flag
ENV = 'staging'
# base api
VUE_APP_BASE_API = 'http://test.api.watermarker-v1.moviebook.cni'