Giter VIP home page Giter VIP logo

vue-axios-github's Issues

嵌套路由时,子路由需要重复设置meta:{requireAuth:true}

{ path: '/parent', name: 'parent', component: Parent, meta: { requireAuth: true }, children: [ { name: 'child', path: 'child', component: Child } ] }
当访问/parent/child的时候并没有执行权限验证,所以建议在beforeEach中的判断由to.meta.requireAuth改为to.matched.some(r => r.meta.requireAuth),这样的话父路由设置requireAuth后子路由就不用设置了
个人愚见,错误之处还请指正😝

后端401时,axios没能拦截到未授权信息

// http response 拦截器 axios.interceptors.response.use( response => { return response; }, error => { if (error.response) { switch (error.response.status) { case 401: // 返回 401 清除token信息并跳转到登录页面 store.commit(types.LOGOUT); router.replace({ path: 'login', query: {redirect: router.currentRoute.fullPath} }) } } return Promise.reject(error.response.data) // 返回接口返回的错误信息 });
error.response undefined

token 401判断

这个token 是sessionId 吧
每次http请求, cookie都会带上sessionId
验证没通过 接口也能返回401

如果http头的authorization 带上 sid,
cookie 的sid 后台是不是就不用判断了,
那要后台修改判断方式吗, 会不会降低安全性, 因为cookie字段可以用httpOnly保护起来,

而存储在vuex 或者 sessionStorage中, 给了xss机会 ;

vuex 浏览器刷新就没掉了

if (store.state.token) { // 通过vuex state获取当前的token是否存在 next(); }

所以应该要放到sessionStorage或者localStorage里吧?

如何让部分请求自定义拦截器

axios的interceptors全局的拦截器所以的请求都会被处理,如果我有一个请求不想用到这个拦截器想自定义回调的话,需要怎么做呢

不会出现循环引用吗?

入口main.js中import了http,而http中import了router,router中import了repository,repository中import了http

关于token存值的疑问

为什么在router.js 里面要根据 localStrorage 里面有没有 token 重新给state赋值 token

https://github.com/superman66/vue-axios-github/blob/master/src/router.js#L37

我的疑问

不能直接在 Line 48 这样判断吗?

if (localStrorage.getItem('token')) {
    next();
}

我的理解

Line 37的做法其实就是每次重载页面把 token 存在了 state 里面,是为了方便存在 state 里面的token 以后使用 ?

如果有时间请帮忙解答一下我的疑惑

谢谢,学习了

因为都是团队合作写项目,这一块权限的配置,都是leader在做。学习了

在一个页面有多个请求返回401的情况下 登入会有点问题

比如我在某个页面有两个请求,现在我把localStorage里面的token手动改掉刷新,问题就来了,因为http的请求拦截在401的情况下
image总是会把fullPath当做redirect传递过去 两次的请求返回都是401且返回时间不在同一个时间点导致前面一个401到登入页来了 后面一个401又把登入页面的fullPath给到redirect。这时的登入页会有两个redirect组成的路由这种情况怎么处理

Vue.prototype.axios = axios;报错

错误提示为:Cannot set property axios of #<Vue$3> which has only a getter at eval ,都是按照readme文档来搭建的。然后提示这个错误

你好!关于刷新页面,Vuex实例store中保存的token为什么要重新获取。

问题产生:
我在登录的时候如你一样去把token,user放入了state中,我设想的情况时,既然store挂载的是一个vue实例,那么不论什么情况,只要不重建vue实例,store中的数据就不该丢失。但是我就是在刷新的时候,store中的数据会清空。这和我预期不符。参考你的代码,有一段是刷新之后重新获取token的代码。(router.js文件中38行),想必你能为我解答这个疑惑!

我之前也用vueResource使用过,后面发现有点问题.

按照这个思路
是通过判断vuex里面的token是否存在来允许是否进入该路由.
我当时的需求是通过判断权限.可以说也是从vuex里面拿的数据
但有个问题就是
当按了F5刷新.
这时候进入router.forEach是比 app.beforeCreated要早执行的
这时候是不存在store里面的相关信息.所以就直接跳去login.
也是说每次按F5都要重新登陆一遍.
不知道你的会不会有这种情况.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.