In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "how to generate token in vue and save to local storage", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to generate token in vue and save it to local storage" can help you solve your doubts.
Let's first review token:
Token authentication is a very important part of RESTFUL.api. Through token authentication and token setting, the backend will have an API passed to the foreground:
Http://localhost/yiiserver/web/index.php/token?client_appid=aaa&client_appkey=bbb
In fact, it is to generate a token from the user table.
The client_id here is equivalent to the user name, and the client_key is equivalent to the password, so the background will generate a client_token, and we need to save the token to the client.
The front-end resources are generally placed in another server, so the background needs to carry out cross-domain operations and add header files to the php code.
/ / is our commonly used access-control-allow-originheader ("Access-Control-Allow-Origin: *"); header ("Access-Control-Allow-Methods:GET,POST"); header ("Access-Control-Allow-Headers:X-Requeted-With,content-type,if-modified-since")
In this way, the background cross-domain can be realized successfully.
The foreground project uses vuex for state management, which is divided into three parts: state, mutations and actions. We define a userLogin method in actions, send http to request backend server data, and the returned response data is saved in the setUser in mutations. Because the userLogin method defined in actions is called by users when logging in, the userLogin method is also used in userLogin.vue.
After reading this, the article "how to generate token in vue and save it to local storage" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.