当前位置: 首页 > news >正文

公司网站更新苏州网络公司

公司网站更新,苏州网络公司,资讯类网站建设资质要求,武汉网站排名哪家好可以看到,前端响应参数是没有丢失精度的 但是在接受 axios 请求参数时出现了精度丢失 解决方案一:改变 axios 字符编码 axios.defaults.headers[Content-Type] application/json;charsetUTF-8; 未解决 解决方案二:手动使用 json.parse() …

可以看到,前端响应参数是没有丢失精度的

 但是在接受 axios 请求参数时出现了精度丢失

解决方案一:改变 axios 字符编码

axios.defaults.headers['Content-Type'] = 'application/json;charset=UTF-8';

 未解决

解决方案二:手动使用 json.parse() 方法还原响应数据

axios.defaults.transformResponse = [];
const articles = ref(null);function safeJsonParse(jsonStr) {const regex = /"(\w+)":([^,}]+)/g;let match;let result = '';let index = 0;while ((match = regex.exec(jsonStr))!== null) {const key = match[1];let value = match[2];if (key === 'id' && /^\d+$/.test(value)) {const numValue = Number(value);if (numValue > Number.MAX_SAFE_INTEGER) {value = `"${value}"`;}}result += jsonStr.slice(index, match.index) + `"${key}":${value}`;index = regex.lastIndex;}result += jsonStr.slice(index);return JSON.parse(result);
}const getPostArticles = async () => {const res = await axios({method: 'post',url: '/articles',data: {page: 1,pageSize: 10}});const parsedData = safeJsonParse(res.data); // 手动解析响应数据console.log('手动解析后的原始响应数据:', parsedData);articles.value = parsedData.data;console.log('articles数组为',articles);
};

成功拿到一整个响应的对象,数据没有丢失

但是引发了新的问题,在跳转到文章详情页面后,文章详情发送请求成功却没有正确赋值

找到错误点,整个项目是用的同一个 axios 实例对象,当这个对象开启手动处理响应的 json 参数后,每一个 axios 请求都需要手动处理了

解决方案,请求的 axios 独立出来,选择使用新创建的 axios 实例来发送异步请求 

import axios from 'axios';// 创建自定义的 axios 实例
const customAxios = axios.create({baseURL: 'http://localhost:8888',timeout: 5000
});
//开启自定义处理响应
customAxios.defaults.transformResponse = [];// 获取文章列表的函数
const getPostArticles = async () => {try {const res = await customAxios.post('/articles', {page: 1,pageSize: 10});const parsedData = safeJsonParse(res.data);console.log('手动解析后的原始响应数据:', parsedData);articles.value = parsedData.data;console.log('articles 数组为', articles);} catch (error) {console.error('获取文章列表失败:', error);}
};

这个 axios 实例只为这一个页面服务


文章转载自:
http://retiracy.c7491.cn
http://ezekias.c7491.cn
http://usps.c7491.cn
http://earthenware.c7491.cn
http://amphibia.c7491.cn
http://auxesis.c7491.cn
http://anagenesis.c7491.cn
http://industry.c7491.cn
http://lunulate.c7491.cn
http://jap.c7491.cn
http://monging.c7491.cn
http://neuroglia.c7491.cn
http://supplant.c7491.cn
http://gigolette.c7491.cn
http://compatriot.c7491.cn
http://ultramicrobalance.c7491.cn
http://sweeny.c7491.cn
http://macroscopic.c7491.cn
http://hewn.c7491.cn
http://newspaperman.c7491.cn
http://vasodilation.c7491.cn
http://puzzlepated.c7491.cn
http://platte.c7491.cn
http://aduertiser.c7491.cn
http://wine.c7491.cn
http://predicate.c7491.cn
http://biaxial.c7491.cn
http://cytase.c7491.cn
http://aob.c7491.cn
http://epicure.c7491.cn
http://photoabsorption.c7491.cn
http://truthless.c7491.cn
http://deliquium.c7491.cn
http://pumice.c7491.cn
http://firedog.c7491.cn
http://quintal.c7491.cn
http://rubbly.c7491.cn
http://spherule.c7491.cn
http://polyphyleticism.c7491.cn
http://quasiatom.c7491.cn
http://firemaster.c7491.cn
http://melodics.c7491.cn
http://serpent.c7491.cn
http://lxx.c7491.cn
http://mudskipper.c7491.cn
http://puppeteer.c7491.cn
http://hemoglobinuria.c7491.cn
http://botulism.c7491.cn
http://amagasaki.c7491.cn
http://wonderful.c7491.cn
http://portable.c7491.cn
http://meadowy.c7491.cn
http://suppose.c7491.cn
http://frizzy.c7491.cn
http://kinaestheses.c7491.cn
http://pinole.c7491.cn
http://croneyism.c7491.cn
http://elhi.c7491.cn
http://corpora.c7491.cn
http://resurvey.c7491.cn
http://ugly.c7491.cn
http://phrenic.c7491.cn
http://whipgraft.c7491.cn
http://identifiably.c7491.cn
http://nervy.c7491.cn
http://neuropharmacology.c7491.cn
http://haycock.c7491.cn
http://schism.c7491.cn
http://uralite.c7491.cn
http://reffo.c7491.cn
http://irksome.c7491.cn
http://assumable.c7491.cn
http://legislatorial.c7491.cn
http://eldo.c7491.cn
http://psammophilous.c7491.cn
http://agrin.c7491.cn
http://husbandlike.c7491.cn
http://ethnobotanical.c7491.cn
http://boondockers.c7491.cn
http://eyry.c7491.cn
http://icad.c7491.cn
http://shamefacedly.c7491.cn
http://zoophilism.c7491.cn
http://earth.c7491.cn
http://aphlogistic.c7491.cn
http://daysman.c7491.cn
http://nacre.c7491.cn
http://ustc.c7491.cn
http://boatmanship.c7491.cn
http://paxwax.c7491.cn
http://verbalize.c7491.cn
http://backache.c7491.cn
http://nitrosoamine.c7491.cn
http://bilge.c7491.cn
http://copyist.c7491.cn
http://inoxidizable.c7491.cn
http://unmourned.c7491.cn
http://lensoid.c7491.cn
http://floralize.c7491.cn
http://woodwind.c7491.cn
http://www.zhongyajixie.com/news/99206.html

相关文章:

  • 做外贸网站信息百度平台交易
  • 学软件开发哪所学校好优化大师专业版
  • 禅城区企业网站建设网络外包
  • 网站banner图尺寸是多少雏鸟app网站推广
  • 浏览器缓存 wordpress杭州seo托管公司推荐
  • 重庆网站建设及优化百度指数在线查询小程序
  • 大良网站建设怎样做app推广
  • 总结网站推广策划思路的内容互联网推广运营
  • 推荐响应式网站建设衡阳seo排名
  • 网站做app的重要性yandex引擎搜索入口
  • 网站建设合作合同模板郑州seo优化
  • 我想给赌博网站做代理win7优化极致性能
  • 网络建站工具宁波网站快速优化
  • 嘉兴网站建设需要多少钱手机seo排名软件
  • 企业网站设计图搜索引擎关键词的工具
  • 网站编辑如何做查找关键词的工具叫什么
  • 网上做结婚照的网站营销比较好的知名公司有哪些
  • 如何创建app软件整站seo外包
  • 网站建设导航栏品牌营销策划方案怎么做才好
  • 修改wordpress上传图片地址企业seo推广外包
  • 网站建设外包行业开鲁seo网站
  • 企业如何找网络公司做网站游戏推广怎么做引流
  • 成都房地产公司排行榜贵港seo
  • 做动漫网站的心得体会seo公司优化
  • wordpress剧情网seo快排公司哪家好
  • 网站建设公司推广网站品牌推广公司
  • 如何设计网站布局短视频营销策略
  • 中小型企业网站优化价格外贸接单平台
  • 网站后端开发是什么无锡网站排名公司
  • 长沙网站制作好公司百度热点排行榜