XiaoRuby
2023-08-14 4fb8b960f98bb1f2b3eaf39b7479ddbe9e53c5a5
src/main.js
@@ -40,11 +40,19 @@
  }
  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)
@@ -89,18 +97,18 @@
})
// 路由拦截器
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',