1、現(xiàn)象:axios從服務(wù)端請(qǐng)求。返回的數(shù)據(jù)有個(gè)id字段為int類型,值為6203146187571204548。axios默認(rèn)會(huì)將數(shù)據(jù)轉(zhuǎn)為對(duì)象。此時(shí)這個(gè)值就被轉(zhuǎn)為6203146187571204000了
2、解決方式:在config中自定義轉(zhuǎn)換函數(shù):此處將supplierId的值由number轉(zhuǎn)為字符串,再轉(zhuǎn)為對(duì)象返回
// 解決字段為數(shù)字且超出了js最大數(shù)字,導(dǎo)致精度確實(shí)。故轉(zhuǎn)為字符串
const transformResponse = function (res) {
/* eslint-disable*/
res = res.replace(/\"supplierId\":(\d+)/g, '"supplierId":"$1"')
LOG.info(res)
return JSON.parse(res)
}
const instance = axios.create({
baseURL: baseUrl,
transformResponse
})