Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

vue的token问题

请问一下,做的混合app,如果app登录了首页携带token我拿到保存到本地没问题,如果没登录进入页面,点击关注的时候跳到app登录页了app返给我了token,怎么把它放到封装好的http请求里面,因为之前的token是获取的本地存储,就执行了一次,现在获取到了加不到请求头,我用的vuex,能单独改header吗
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

无token时会跳到app登录页,登录成功跳转到h5,(token带在链接或者客户端提供获取方法);
你在 router.beforeEach 里面判断 并 获取token(从链接上获取或者其他方式),拿到commit,顺便再 存储就行了;
token添加就在http封装里面加,你的没问题;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...