Official answer:

Tokens are generated on the server side. If the front end uses the user name and password to request authentication from the server, the server returns the Token to the front end. The front-end can prove its legitimacy with tokens at every request.

Based on the engineer’s understanding:

Token is equivalent to the unique identifier of the client login account. When making some data requests, the background will require the token to be carried in the request header. If there is no token or the token has expired, the client will return the response data at this time, and the front-end will parse the data to determine that the token has expired. Still not carrying token, and then let the user do the corresponding action.

In short, tokens are essential when requesting data from the background. Without tokens, the background will either not return the data for the response, or it will return some irrelevant data.

Verifying a Local Token

Some data cannot be requested if the request header does not carry token, and the server will return us empty data or directly report an error. In this case, we can perform front-end verification of the existence of local token when requesting data.

If it exists, we send the request. If it doesn’t exist, we remind the user to log in or we can’t view the data without logging in. After the user waits, we save the token value returned to us from the background locally.

3. The request header carries a token.

4. About login and registration.

Login registration has always been a front-end programmer around a requirement, no matter what you are writing projects will use login registration, when you write code to login registration will probably be divided into two modules:

  • Password login Authenticates one of the user name, account number, and mobile phone number when writing the password. Of course, these authentications must be written in the front end, otherwise each time a request is sent to the server, the server performance will be occupied. Generally, it is to determine whether the password is empty, format, and length.

  • This login method involves the first login, which is equivalent to registration, and after registration is to set a password, personal information, or to a page these depends on the needs of the project, different project needs are also different.

5. About encapsulating AXIos and encapsulating interfaces

  • Encapsulation axios

  • Encapsulated interface

Create a new request.js file, usually under utils, and then pour into the axios.js file that you just wrapped.

Create a new object, add a method to the object, the method is to request the interface function encapsulation, and then export the object by default;

Import the requeat.js file in main.js, and then mount the object on the Vue prototype. “, then pour into the wrapped axios.js file, create a new object, and add methods to the object;

The approach is to request functional encapsulation of the interface, export the object by default, import requeat.js in main.js, and then mount the object on the Vue prototype.

Finally, in order to facilitate everyone’s learning test, we specially prepared a 13G super practical dry goods learning resources, involving very comprehensive content. Include software learning roadmap, video, and more than 50 days of class 16 assault on practical projects, more than 80 software testing with software, 37 test documentation, 70 software test related issues, 40 level testing experience article, thousands of test questions, sharing, and 2021 bible software testing interview, there are all kinds of selected software testing job resume, Hope to help you…

Pay attention to my public number: [programmer two black] can get this information!

Recommended reading

Well paid programmers can’t escape being 35… How can we save ourselves when our abilities are out of sync with our age

Graduated from college and started selling… Unwilling to accept the status quo, the road to self-help testing

From crown to unemployment, finally choose software testing, looking back on the road, I was lucky!