Local Node experiment.

background

During a development process, data transmitted from the background (Java) was lost. After the background query log, it was found to be normal. At first I didn’t think it was Java long converting to JS number.

positioning

Databases were checked, packages were captured, and the problem was finally located.

The most experienced web backend will pass long numbers as strings.

Online solutions also tend to be background solutions.

To solve

In the background, the students are confused.

It’s solved on the front end.

Introduce the toolkit.

const JSONbig = require("json-bigint") ({storeAsString: true });
Copy the code

To decorate request-to-data, this project uses AXIOS for network requests.

Configure axiOS’s transformResponse property.

    transformResponse: function(data: any) {
      let result = JSONbig.parse(data);
      return result;
    }
Copy the code

I can convert any number in the background that exceeds the JS number to a string.

Maybe at this point, everyone will think of Bigint, but I did not study the solution about Bigint after solving the problem ~