Home >Web Front-end >JS Tutorial >What is qs in react

What is qs in react

coldplay.xixi
coldplay.xixiOriginal
2020-12-11 11:41:582688browse

QS in react is a package managed by the npm warehouse. It is a library that adds some security to query string parsing and serialization strings. It can be installed through the [npm install qs] command.

What is qs in react

#The operating environment of this tutorial: windows7 system, React17 version, thinkpad t480 computer.

qs in react:

qs is a package managed by an npm warehouse, which adds some security A library for query string parsing and string serialization. It can be installed through the npm install qs command.

react uses qs:

1, qs.parse()Parse the URL into the form of an object

import  Qs from 'qs';
let url = 'method=query_sql_dataset_data&projectId=85&appToken=7d22e38e-5717-11e7-907b-a6006ad3dba0';
Qs.parse(url);
console.log(Qs.parse(url));

Output Result

{
    method:'query_sql_dataset_data',
    projectId:'85',
    appToken:'7d22e38e-5717-11e7-907b-a6006ad3dba0'
}

2, qs.stringify()Serialize the object into the form of a URL and splice it with & (can be used to send query conditions)

import  Qs from 'qs';
let obj= {
     method: "query_sql_dataset_data",
     projectId: "85",
     appToken: "7d22e38e-5717-11e7-907b-a6006ad3dba0",
     datasetId: " 12564701"
   };
Qs.stringify(obj);
console.log(Qs.stringify(obj));

The output is :

method=query_sql_dataset_data&projectId=85&appToken=7d22e38e-5717-11e7-907b-a6006ad3dba0&datasetId=%12564701

It should be noted here that the stringify method also exists in JSON, but the difference between the two is obvious, as shown below:

{"uid":"cs11","pwd":"000000als","username":"cs11","password":"000000als"}
uid=cs11&pwd=000000als&username=cs11&password=000000als

As shown above, the former It is processed using JSON.stringify(param), and the latter is processed using Qs.stringify(param).

Related free learning recommendations: javascript(Video)

The above is the detailed content of What is qs in react. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more