前端大数字导致的数据请求错误
最佳解决方案:
后端修改接口将数字类型转化为字符串类型
前端方案:
// 下载并使用第三方包 json-bigint 可以解决大数字问题
# yarn add amfe-flexible
npm i json-bigint
// 在组件中倒入并使用
import jsonbig from 'json-bigint'
const request = axios.create({
baseURL: 'http://xxxxxxxxxxxxxx/',
// axios 中transformResponse中修改json转换方法
transformResponse: [
function (data) {
try {
return jsonbig.parse(data)
} catch (err) {
return data
}
}
]
})