| | |
| | | } |
| | | if (token) { |
| | | config.headers['token'] = "" + token |
| | | config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | // config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | // config.headers['Content-Type'] = 'application/json' |
| | | } |
| | | // console.log(config) |
| | | if (config.method === 'post' || config.method === 'put') { |
| | | |
| | | config.data = qs.stringify(config.data) |
| | | } |
| | | if(config.headers['Content-Type'] =='application/json'){ |
| | | config.data = qs.parse(config.data) |
| | | // console.log(config.data) |
| | | } |
| | | |
| | | return config |
| | | }, function(error) { |
| | | return Promise.reject(error) |
| | |
| | | }) |
| | | |
| | | // 路由拦截器 |
| | | router.beforeEach((to, from, next) => { |
| | | // 路径为product时验证是否登录,没有跳转至登录页面 |
| | | if (to.path.indexOf('/') > -1 && to.path.indexOf('/enter') != 0) { |
| | | if (sessionStorage.getItem('token') == null || sessionStorage.getItem('token') == '' || sessionStorage.getItem( |
| | | 'token') == undefined) { |
| | | next({ |
| | | path: '/enter' |
| | | }) |
| | | } |
| | | } |
| | | next() |
| | | }); |
| | | // router.beforeEach((to, from, next) => { |
| | | // // 路径为product时验证是否登录,没有跳转至登录页面 |
| | | // if (to.path.indexOf('/') > -1 && to.path.indexOf('/enter') != 0) { |
| | | // if (sessionStorage.getItem('token') == null || sessionStorage.getItem('token') == '' || sessionStorage.getItem( |
| | | // 'token') == undefined) { |
| | | // next({ |
| | | // path: '/enter' |
| | | // }) |
| | | // } |
| | | // } |
| | | // next() |
| | | // }); |
| | | |
| | | new Vue({ |
| | | el: '#app', |